Skip to content

Commit

Permalink
refactor: rename test_data to testdata and some lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: ankitm123 <[email protected]>
  • Loading branch information
ankitm123 committed Jul 9, 2022
1 parent d90d8e3 commit 5c9f9b4
Show file tree
Hide file tree
Showing 159 changed files with 760 additions and 771 deletions.
10 changes: 7 additions & 3 deletions hack/linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Installing GolangCI-Lint"
${DIR}/install_golint.sh -b $GOPATH/bin v1.42.1
linterVersion="$(golangci-lint --version | awk '{print $4}')"

expectedLinterVersion=1.46.2

if [ "${linterVersion}" != "${expectedLinterVersion}" ]; then
echo "Install GolangCI-Lint version ${expectedLinterVersion}"
exit 1
fi

export GO111MODULE=on
Expand Down
6 changes: 3 additions & 3 deletions scm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import (

var (
// ErrNotFound indicates a resource is not found.
ErrNotFound = errors.New("Not Found")
ErrNotFound = errors.New("not Found")

// ErrNotSupported indicates a resource endpoint is not
// supported or implemented.
ErrNotSupported = errors.New("Not Supported")
ErrNotSupported = errors.New("not Supported")

// ErrNotAuthorized indicates the request is not
// authorized or the user does not have access to the
// resource.
ErrNotAuthorized = errors.New("Not Authorized")
ErrNotAuthorized = errors.New("not Authorized")

// ErrForbidden indicates the user does not have access to
// the resource, this is similar to 401, but in this case,
Expand Down
2 changes: 1 addition & 1 deletion scm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ToState(s string) State {

// MarshalJSON marshals State to JSON
func (s State) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, s.String())), nil
return []byte(fmt.Sprintf(`%q`, s.String())), nil
}

// UnmarshalJSON unmarshals JSON to State
Expand Down
4 changes: 2 additions & 2 deletions scm/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type (
Find(ctx context.Context, repoFullName string, deploymentID string) (*Deployment, *Response, error)

// List returns a list of deployments.
List(ctx context.Context, repoFullName string, opts ListOptions) ([]*Deployment, *Response, error)
List(ctx context.Context, repoFullName string, opts *ListOptions) ([]*Deployment, *Response, error)

// Create creates a new deployment.
Create(ctx context.Context, repoFullName string, deployment *DeploymentInput) (*Deployment, *Response, error)
Expand All @@ -87,7 +87,7 @@ type (
FindStatus(ctx context.Context, repoFullName string, deploymentID string, statusID string) (*DeploymentStatus, *Response, error)

// List returns a list of deployments.
ListStatus(ctx context.Context, repoFullName string, deploymentID string, options ListOptions) ([]*DeploymentStatus, *Response, error)
ListStatus(ctx context.Context, repoFullName string, deploymentID string, options *ListOptions) ([]*DeploymentStatus, *Response, error)

// Create creates a new deployment.
CreateStatus(ctx context.Context, repoFullName string, deploymentID string, deployment *DeploymentStatusInput) (*DeploymentStatus, *Response, error)
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/bitbucket/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package bitbucket
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/jenkins-x/go-scm/scm"
Expand All @@ -32,7 +32,7 @@ func TestContentFind(t *testing.T) {
}

want := new(scm.Content)
raw, _ := ioutil.ReadFile("testdata/content.json.golden")
raw, _ := os.ReadFile("testdata/content.json.golden")
err = json.Unmarshal(raw, want)
if err != nil {
t.Error(err)
Expand Down
8 changes: 4 additions & 4 deletions scm/driver/bitbucket/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *gitService) FindTag(ctx context.Context, repo, name string) (*scm.Refer
return convertTag(out), res, err
}

func (s *gitService) ListBranches(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Reference, *scm.Response, error) {
func (s *gitService) ListBranches(ctx context.Context, repo string, opts *scm.ListOptions) ([]*scm.Reference, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/refs/branches?%s", repo, encodeListOptions(opts))
out := new(branches)
res, err := s.client.do(ctx, "GET", path, nil, out)
Expand All @@ -99,7 +99,7 @@ func (s *gitService) ListCommits(ctx context.Context, repo string, opts scm.Comm
return convertCommitList(out), res, err
}

func (s *gitService) ListTags(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Reference, *scm.Response, error) {
func (s *gitService) ListTags(ctx context.Context, repo string, opts *scm.ListOptions) ([]*scm.Reference, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/refs/tags?%s", repo, encodeListOptions(opts))
out := new(branches)
res, err := s.client.do(ctx, "GET", path, nil, &out)
Expand All @@ -110,7 +110,7 @@ func (s *gitService) ListTags(ctx context.Context, repo string, opts scm.ListOpt
return convertTagList(out), res, err
}

func (s *gitService) ListChanges(ctx context.Context, repo, ref string, opts scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
func (s *gitService) ListChanges(ctx context.Context, repo, ref string, opts *scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/diffstat/%s?%s", repo, ref, encodeListOptions(opts))
out := new(diffstats)
res, err := s.client.do(ctx, "GET", path, nil, &out)
Expand All @@ -121,7 +121,7 @@ func (s *gitService) ListChanges(ctx context.Context, repo, ref string, opts scm
return convertDiffstats(out), res, err
}

func (s *gitService) CompareCommits(ctx context.Context, repo, ref1, ref2 string, opts scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
func (s *gitService) CompareCommits(ctx context.Context, repo, ref1, ref2 string, opts *scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/diffstat/%s..%s?%s", repo, ref1, ref2, encodeListOptions(opts))
out := new(diffstats)
res, err := s.client.do(ctx, "GET", path, nil, &out)
Expand Down
26 changes: 13 additions & 13 deletions scm/driver/bitbucket/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package bitbucket
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/jenkins-x/go-scm/scm"
Expand All @@ -32,7 +32,7 @@ func TestGitFindCommit(t *testing.T) {
}

want := new(scm.Commit)
raw, _ := ioutil.ReadFile("testdata/commit.json.golden")
raw, _ := os.ReadFile("testdata/commit.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestGitFindBranch(t *testing.T) {
}

want := new(scm.Reference)
raw, _ := ioutil.ReadFile("testdata/branch.json.golden")
raw, _ := os.ReadFile("testdata/branch.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestGitFindTag(t *testing.T) {
}

want := new(scm.Reference)
raw, _ := ioutil.ReadFile("testdata/tag.json.golden")
raw, _ := os.ReadFile("testdata/tag.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestGitListCommits(t *testing.T) {
}

want := []*scm.Commit{}
raw, _ := ioutil.ReadFile("testdata/commits.json.golden")
raw, _ := os.ReadFile("testdata/commits.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand All @@ -144,13 +144,13 @@ func TestGitListBranches(t *testing.T) {
File("testdata/branches.json")

client, _ := New("https://api.bitbucket.org")
got, res, err := client.Git.ListBranches(context.Background(), "atlassian/stash-example-plugin", scm.ListOptions{Page: 1, Size: 30})
got, res, err := client.Git.ListBranches(context.Background(), "atlassian/stash-example-plugin", &scm.ListOptions{Page: 1, Size: 30})
if err != nil {
t.Error(err)
}

want := []*scm.Reference{}
raw, _ := ioutil.ReadFile("testdata/branches.json.golden")
raw, _ := os.ReadFile("testdata/branches.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand All @@ -176,13 +176,13 @@ func TestGitListTags(t *testing.T) {
File("testdata/tags.json")

client, _ := New("https://api.bitbucket.org")
got, res, err := client.Git.ListTags(context.Background(), "atlassian/atlaskit", scm.ListOptions{Page: 1, Size: 30})
got, res, err := client.Git.ListTags(context.Background(), "atlassian/atlaskit", &scm.ListOptions{Page: 1, Size: 30})
if err != nil {
t.Error(err)
}

want := []*scm.Reference{}
raw, _ := ioutil.ReadFile("testdata/tags.json.golden")
raw, _ := os.ReadFile("testdata/tags.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand All @@ -208,13 +208,13 @@ func TestGitListChanges(t *testing.T) {
File("testdata/diffstat.json")

client, _ := New("https://api.bitbucket.org")
got, _, err := client.Git.ListChanges(context.Background(), "atlassian/atlaskit", "425863f9dbe56d70c8dcdbf2e4e0805e85591fcc", scm.ListOptions{Page: 1, Size: 30})
got, _, err := client.Git.ListChanges(context.Background(), "atlassian/atlaskit", "425863f9dbe56d70c8dcdbf2e4e0805e85591fcc", &scm.ListOptions{Page: 1, Size: 30})
if err != nil {
t.Error(err)
}

want := []*scm.Change{}
raw, _ := ioutil.ReadFile("testdata/diffstat.json.golden")
raw, _ := os.ReadFile("testdata/diffstat.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand All @@ -238,13 +238,13 @@ func TestGitCompareCommits(t *testing.T) {
File("testdata/diffstat.json")

client, _ := New("https://api.bitbucket.org")
got, _, err := client.Git.CompareCommits(context.Background(), "atlassian/atlaskit", "anarbitraryshabutnotatallarbitrarylength", "425863f9dbe56d70c8dcdbf2e4e0805e85591fcc", scm.ListOptions{Page: 1, Size: 30})
got, _, err := client.Git.CompareCommits(context.Background(), "atlassian/atlaskit", "anarbitraryshabutnotatallarbitrarylength", "425863f9dbe56d70c8dcdbf2e4e0805e85591fcc", &scm.ListOptions{Page: 1, Size: 30})
if err != nil {
t.Error(err)
}

want := []*scm.Change{}
raw, _ := ioutil.ReadFile("testdata/diffstat.json.golden")
raw, _ := os.ReadFile("testdata/diffstat.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand Down
6 changes: 3 additions & 3 deletions scm/driver/bitbucket/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func (s *issueService) UnassignIssue(ctx context.Context, repo string, number in
return nil, scm.ErrNotSupported
}

func (s *issueService) ListEvents(context.Context, string, int, scm.ListOptions) ([]*scm.ListedIssueEvent, *scm.Response, error) {
func (s *issueService) ListEvents(context.Context, string, int, *scm.ListOptions) ([]*scm.ListedIssueEvent, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

func (s *issueService) ListLabels(ctx context.Context, repo string, number int, opts scm.ListOptions) ([]*scm.Label, *scm.Response, error) {
func (s *issueService) ListLabels(ctx context.Context, repo string, number int, opts *scm.ListOptions) ([]*scm.Label, *scm.Response, error) {
// Get all comments, parse out labels (removing and added based off time)
cs, res, err := s.ListComments(ctx, repo, number, opts)
if err == nil {
Expand Down Expand Up @@ -77,7 +77,7 @@ func convertIssueCommentList(from []*issueComment) []*scm.Comment {
return to
}

func (s *issueService) ListComments(ctx context.Context, repo string, index int, opts scm.ListOptions) ([]*scm.Comment, *scm.Response, error) {
func (s *issueService) ListComments(ctx context.Context, repo string, index int, opts *scm.ListOptions) ([]*scm.Comment, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/pullrequests/%d/comments?%s", repo, index, encodeListOptions(opts))
out := []*issueComment{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
Expand Down
6 changes: 3 additions & 3 deletions scm/driver/bitbucket/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestIssueList(t *testing.T) {
}

func TestIssueListComments(t *testing.T) {
// TODO
// TODO: add test later
}

func TestIssueCreate(t *testing.T) {
Expand All @@ -44,11 +44,11 @@ func TestIssueCreate(t *testing.T) {
}

func TestIssueCreateComment(t *testing.T) {
// TODO
// TODO: add test later
}

func TestIssueCommentDelete(t *testing.T) {
// TODO
// TODO: add test later
}

func TestIssueClose(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions scm/driver/bitbucket/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *organizationService) Delete(context.Context, string) (*scm.Response, er
}

func (s *organizationService) IsMember(ctx context.Context, org, user string) (bool, *scm.Response, error) {
path := fmt.Sprintf("2.0/workspaces/%s/permissions?q=user.account_id=\"%s\"", org, user)
path := fmt.Sprintf("2.0/workspaces/%s/permissions?q=user.account_id=%q", org, user)
result := new(organizationMemberships)
res, err := s.client.do(ctx, "GET", path, nil, result)
if err != nil {
Expand All @@ -48,15 +48,15 @@ func (s *organizationService) IsAdmin(ctx context.Context, org, user string) (bo
return false, nil, scm.ErrNotSupported
}

func (s *organizationService) ListTeams(ctx context.Context, org string, ops scm.ListOptions) ([]*scm.Team, *scm.Response, error) {
func (s *organizationService) ListTeams(ctx context.Context, org string, ops *scm.ListOptions) ([]*scm.Team, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

func (s *organizationService) ListTeamMembers(ctx context.Context, id int, role string, ops scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) {
func (s *organizationService) ListTeamMembers(ctx context.Context, id int, role string, ops *scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

func (s *organizationService) ListOrgMembers(ctx context.Context, org string, ops scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) {
func (s *organizationService) ListOrgMembers(ctx context.Context, org string, ops *scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

Expand All @@ -67,7 +67,7 @@ func (s *organizationService) Find(ctx context.Context, name string) (*scm.Organ
return convertOrganization(out), res, err
}

func (s *organizationService) List(ctx context.Context, opts scm.ListOptions) ([]*scm.Organization, *scm.Response, error) {
func (s *organizationService) List(ctx context.Context, opts *scm.ListOptions) ([]*scm.Organization, *scm.Response, error) {
path := fmt.Sprintf("2.0/workspaces?%s", encodeListRoleOptions(opts))
out := new(organizationList)
res, err := s.client.do(ctx, "GET", path, nil, out)
Expand All @@ -78,15 +78,15 @@ func (s *organizationService) List(ctx context.Context, opts scm.ListOptions) ([
return convertOrganizationList(out), res, err
}

func (s *organizationService) ListPendingInvitations(ctx context.Context, org string, opts scm.ListOptions) ([]*scm.OrganizationPendingInvite, *scm.Response, error) {
func (s *organizationService) ListPendingInvitations(ctx context.Context, org string, opts *scm.ListOptions) ([]*scm.OrganizationPendingInvite, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

func (s *organizationService) AcceptOrganizationInvitation(ctx context.Context, org string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *organizationService) ListMemberships(ctx context.Context, opts scm.ListOptions) ([]*scm.Membership, *scm.Response, error) {
func (s *organizationService) ListMemberships(ctx context.Context, opts *scm.ListOptions) ([]*scm.Membership, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

Expand Down
8 changes: 4 additions & 4 deletions scm/driver/bitbucket/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package bitbucket
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -29,7 +29,7 @@ func TestOrganizationFind(t *testing.T) {
}

want := new(scm.Organization)
raw, _ := ioutil.ReadFile("testdata/workspace.json.golden")
raw, _ := os.ReadFile("testdata/workspace.json.golden")
err = json.Unmarshal(raw, want)
if err != nil {
t.Error(err)
Expand All @@ -50,13 +50,13 @@ func TestOrganizationList(t *testing.T) {
Type("application/json").
File("testdata/workspaces.json")
client, _ := New("https://api.bitbucket.org")
got, _, err := client.Organizations.List(context.Background(), scm.ListOptions{Size: 30, Page: 1})
got, _, err := client.Organizations.List(context.Background(), &scm.ListOptions{Size: 30, Page: 1})
if err != nil {
t.Error(err)
}

want := []*scm.Organization{}
raw, _ := ioutil.ReadFile("testdata/workspaces.json.golden")
raw, _ := os.ReadFile("testdata/workspaces.json.golden")
err = json.Unmarshal(raw, &want)
if err != nil {
t.Error(err)
Expand Down
8 changes: 4 additions & 4 deletions scm/driver/bitbucket/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ func convertPRCommentList(from *pullRequestComments) []*scm.Comment {
return to
}

func (s *pullService) ListComments(ctx context.Context, repo string, index int, opts scm.ListOptions) ([]*scm.Comment, *scm.Response, error) {
func (s *pullService) ListComments(ctx context.Context, repo string, index int, opts *scm.ListOptions) ([]*scm.Comment, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/pullrequests/%d/comments?%s", repo, index, encodeListOptions(opts))
out := new(pullRequestComments)
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertPRCommentList(out), res, err
}

func (s *pullService) ListChanges(ctx context.Context, repo string, number int, opts scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
func (s *pullService) ListChanges(ctx context.Context, repo string, number int, opts *scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/pullrequests/%d/diffstat?%s", repo, number, encodeListOptions(opts))
out := new(diffstats)
res, err := s.client.do(ctx, "GET", path, nil, out)
Expand All @@ -176,7 +176,7 @@ func (s *pullService) ListChanges(ctx context.Context, repo string, number int,
return convertDiffstats(out), res, err
}

func (s *pullService) ListLabels(ctx context.Context, repo string, number int, opts scm.ListOptions) ([]*scm.Label, *scm.Response, error) {
func (s *pullService) ListLabels(ctx context.Context, repo string, number int, opts *scm.ListOptions) ([]*scm.Label, *scm.Response, error) {
// Get all comments, parse out labels (removing and added based off time)
cs, res, err := s.ListComments(ctx, repo, number, opts)
if err == nil {
Expand All @@ -198,7 +198,7 @@ func (s *pullService) DeleteLabel(ctx context.Context, repo string, number int,
return res, err
}

func (s *pullService) ListEvents(context.Context, string, int, scm.ListOptions) ([]*scm.ListedIssueEvent, *scm.Response, error) {
func (s *pullService) ListEvents(context.Context, string, int, *scm.ListOptions) ([]*scm.ListedIssueEvent, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

Expand Down
Loading

0 comments on commit 5c9f9b4

Please sign in to comment.