Skip to content

Commit 5c9f9b4

Browse files
committed
refactor: rename test_data to testdata and some lint fixes
Signed-off-by: ankitm123 <[email protected]>
1 parent d90d8e3 commit 5c9f9b4

File tree

159 files changed

+760
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+760
-771
lines changed

hack/linter.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ fi
99

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

12-
if ! [ -x "$(command -v golangci-lint)" ]; then
13-
echo "Installing GolangCI-Lint"
14-
${DIR}/install_golint.sh -b $GOPATH/bin v1.42.1
12+
linterVersion="$(golangci-lint --version | awk '{print $4}')"
13+
14+
expectedLinterVersion=1.46.2
15+
16+
if [ "${linterVersion}" != "${expectedLinterVersion}" ]; then
17+
echo "Install GolangCI-Lint version ${expectedLinterVersion}"
18+
exit 1
1519
fi
1620

1721
export GO111MODULE=on

scm/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import (
1919

2020
var (
2121
// ErrNotFound indicates a resource is not found.
22-
ErrNotFound = errors.New("Not Found")
22+
ErrNotFound = errors.New("not Found")
2323

2424
// ErrNotSupported indicates a resource endpoint is not
2525
// supported or implemented.
26-
ErrNotSupported = errors.New("Not Supported")
26+
ErrNotSupported = errors.New("not Supported")
2727

2828
// ErrNotAuthorized indicates the request is not
2929
// authorized or the user does not have access to the
3030
// resource.
31-
ErrNotAuthorized = errors.New("Not Authorized")
31+
ErrNotAuthorized = errors.New("not Authorized")
3232

3333
// ErrForbidden indicates the user does not have access to
3434
// the resource, this is similar to 401, but in this case,

scm/const.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func ToState(s string) State {
7373

7474
// MarshalJSON marshals State to JSON
7575
func (s State) MarshalJSON() ([]byte, error) {
76-
return []byte(fmt.Sprintf(`"%s"`, s.String())), nil
76+
return []byte(fmt.Sprintf(`%q`, s.String())), nil
7777
}
7878

7979
// UnmarshalJSON unmarshals JSON to State

scm/deploy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type (
7575
Find(ctx context.Context, repoFullName string, deploymentID string) (*Deployment, *Response, error)
7676

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

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

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

9292
// Create creates a new deployment.
9393
CreateStatus(ctx context.Context, repoFullName string, deploymentID string, deployment *DeploymentStatusInput) (*DeploymentStatus, *Response, error)

scm/driver/bitbucket/content_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package bitbucket
77
import (
88
"context"
99
"encoding/json"
10-
"io/ioutil"
10+
"os"
1111
"testing"
1212

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

3434
want := new(scm.Content)
35-
raw, _ := ioutil.ReadFile("testdata/content.json.golden")
35+
raw, _ := os.ReadFile("testdata/content.json.golden")
3636
err = json.Unmarshal(raw, want)
3737
if err != nil {
3838
t.Error(err)

scm/driver/bitbucket/git.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (s *gitService) FindTag(ctx context.Context, repo, name string) (*scm.Refer
7777
return convertTag(out), res, err
7878
}
7979

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

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

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

124-
func (s *gitService) CompareCommits(ctx context.Context, repo, ref1, ref2 string, opts scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
124+
func (s *gitService) CompareCommits(ctx context.Context, repo, ref1, ref2 string, opts *scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
125125
path := fmt.Sprintf("2.0/repositories/%s/diffstat/%s..%s?%s", repo, ref1, ref2, encodeListOptions(opts))
126126
out := new(diffstats)
127127
res, err := s.client.do(ctx, "GET", path, nil, &out)

scm/driver/bitbucket/git_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package bitbucket
77
import (
88
"context"
99
"encoding/json"
10-
"io/ioutil"
10+
"os"
1111
"testing"
1212

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

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

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

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

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

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

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

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

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

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

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

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

246246
want := []*scm.Change{}
247-
raw, _ := ioutil.ReadFile("testdata/diffstat.json.golden")
247+
raw, _ := os.ReadFile("testdata/diffstat.json.golden")
248248
err = json.Unmarshal(raw, &want)
249249
if err != nil {
250250
t.Error(err)

scm/driver/bitbucket/issue.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func (s *issueService) UnassignIssue(ctx context.Context, repo string, number in
3131
return nil, scm.ErrNotSupported
3232
}
3333

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

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

80-
func (s *issueService) ListComments(ctx context.Context, repo string, index int, opts scm.ListOptions) ([]*scm.Comment, *scm.Response, error) {
80+
func (s *issueService) ListComments(ctx context.Context, repo string, index int, opts *scm.ListOptions) ([]*scm.Comment, *scm.Response, error) {
8181
path := fmt.Sprintf("2.0/repositories/%s/pullrequests/%d/comments?%s", repo, index, encodeListOptions(opts))
8282
out := []*issueComment{}
8383
res, err := s.client.do(ctx, "GET", path, nil, &out)

scm/driver/bitbucket/issue_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestIssueList(t *testing.T) {
3333
}
3434

3535
func TestIssueListComments(t *testing.T) {
36-
// TODO
36+
// TODO: add test later
3737
}
3838

3939
func TestIssueCreate(t *testing.T) {
@@ -44,11 +44,11 @@ func TestIssueCreate(t *testing.T) {
4444
}
4545

4646
func TestIssueCreateComment(t *testing.T) {
47-
// TODO
47+
// TODO: add test later
4848
}
4949

5050
func TestIssueCommentDelete(t *testing.T) {
51-
// TODO
51+
// TODO: add test later
5252
}
5353

5454
func TestIssueClose(t *testing.T) {

scm/driver/bitbucket/org.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (s *organizationService) Delete(context.Context, string) (*scm.Response, er
2424
}
2525

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

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

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

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

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

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

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

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

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

scm/driver/bitbucket/org_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package bitbucket
77
import (
88
"context"
99
"encoding/json"
10-
"io/ioutil"
10+
"os"
1111
"testing"
1212

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

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

5858
want := []*scm.Organization{}
59-
raw, _ := ioutil.ReadFile("testdata/workspaces.json.golden")
59+
raw, _ := os.ReadFile("testdata/workspaces.json.golden")
6060
err = json.Unmarshal(raw, &want)
6161
if err != nil {
6262
t.Error(err)

scm/driver/bitbucket/pr.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ func convertPRCommentList(from *pullRequestComments) []*scm.Comment {
158158
return to
159159
}
160160

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

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

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

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

0 commit comments

Comments
 (0)