Skip to content

Commit 81ae429

Browse files
authored
Chore: add golangci-lint (linter) support (#972)
* Chore: add golangci-lint (linter) support * fix test
1 parent 4767b7f commit 81ae429

File tree

140 files changed

+850
-320
lines changed

Some content is hidden

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

140 files changed

+850
-320
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
1-
name: CI
2-
3-
on:
4-
pull_request:
5-
types: [opened, synchronize]
6-
7-
env:
8-
ENV0_API_ENDPOINT: ${{ secrets.ENV0_API_ENDPOINT }}
9-
ENV0_API_KEY: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_KEY }} # API Key for organization 'TF-provider-integration-tests' @ dev
10-
ENV0_API_SECRET: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_SECRET }}
11-
GO_VERSION: "1.21"
12-
TERRAFORM_VERSION: 1.1.7
13-
14-
jobs:
15-
unit-tests:
16-
name: Unit Tests
17-
timeout-minutes: 10
18-
runs-on: ubuntu-20.04
19-
steps:
20-
- name: Install Go
21-
uses: actions/setup-go@v5
22-
with:
23-
go-version: ${{ env.GO_VERSION }}
24-
- name: Checkout code
25-
uses: actions/checkout@v4
26-
- name: Generate mocks
27-
run: |
28-
go install go.uber.org/mock/mockgen@v0.3.0
29-
go generate client/api_client.go
30-
- name: Go fmt
31-
run: |
32-
! go fmt ./... | read
33-
- name: Go vet
34-
run: |
35-
! go vet ./... | read
36-
- name: Go Test
37-
run: go test -v ./...
38-
39-
# See terraform-provider-env0 README for integration tests prerequisites
40-
integration-tests:
41-
name: Integration Tests
42-
runs-on: ubuntu-20.04
43-
container: golang:1.21-alpine3.18
44-
timeout-minutes: 20
45-
steps:
46-
- name: Install Terraform
47-
run: apk add terraform
48-
- name: Checkout code
49-
uses: actions/checkout@v4
50-
- name: Run Harness tests
51-
run: go run tests/harness.go
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
env:
8+
ENV0_API_ENDPOINT: ${{ secrets.ENV0_API_ENDPOINT }}
9+
ENV0_API_KEY: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_KEY }} # API Key for organization 'TF-provider-integration-tests' @ dev
10+
ENV0_API_SECRET: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_SECRET }}
11+
GO_VERSION: "1.21"
12+
TERRAFORM_VERSION: 1.1.7
13+
14+
jobs:
15+
unit-tests:
16+
name: Unit Tests
17+
timeout-minutes: 10
18+
runs-on: ubuntu-20.04
19+
steps:
20+
- name: Install Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: ${{ env.GO_VERSION }}
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
- name: Generate mocks
27+
run: |
28+
go install go.uber.org/mock/mockgen@v0.3.0
29+
go generate client/api_client.go
30+
- name: Go fmt
31+
run: |
32+
! go fmt ./... | read
33+
- name: Go vet
34+
run: |
35+
! go vet ./... | read
36+
- name: golangci-lint
37+
uses: golangci/golangci-lint-action@v6
38+
with:
39+
version: v1.60
40+
- name: Go Test
41+
run: go test -v ./...
42+
43+
# See terraform-provider-env0 README for integration tests prerequisites
44+
integration-tests:
45+
name: Integration Tests
46+
runs-on: ubuntu-20.04
47+
container: golang:1.21-alpine3.18
48+
timeout-minutes: 20
49+
steps:
50+
- name: Install Terraform
51+
run: apk add terraform
52+
- name: Checkout code
53+
uses: actions/checkout@v4
54+
- name: Run Harness tests
55+
run: go run tests/harness.go

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ linters:
33
- errname
44
- errorlint
55
- gocheckcompilerdirectives
6-
- gochecknoglobals
76
- gochecknoinits
87
- goconst
98
- gocritic

client/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func (client *ApiClient) Agents() ([]Agent, error) {
1111
}
1212

1313
var result []Agent
14-
err = client.http.Get("/agents", map[string]string{"organizationId": organizationId}, &result)
15-
if err != nil {
14+
15+
if err := client.http.Get("/agents", map[string]string{"organizationId": organizationId}, &result); err != nil {
1616
return nil, err
1717
}
1818

client/agent_project_assignment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func (client *ApiClient) ProjectsAgentsAssignments() (*ProjectsAgentsAssignments
3030
}
3131

3232
var result ProjectsAgentsAssignments
33+
3334
err = client.http.Get("/agents/projects-assignments", map[string]string{"organizationId": organizationId}, &result)
3435
if err != nil {
3536
return nil, err

client/agent_project_assignment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var _ = Describe("Agent Project Assignment", func() {
3434
var err error
3535

3636
BeforeEach(func() {
37-
mockOrganizationIdCall(organizationId).Times(1)
37+
mockOrganizationIdCall().Times(1)
3838

3939
httpCall = mockHttpClient.EXPECT().
4040
Post("/agents/projects-assignments?organizationId="+organizationId, mapping, gomock.Any()).Times(1).
@@ -59,7 +59,7 @@ var _ = Describe("Agent Project Assignment", func() {
5959
var err error
6060

6161
BeforeEach(func() {
62-
mockOrganizationIdCall(organizationId).Times(1)
62+
mockOrganizationIdCall().Times(1)
6363

6464
httpCall = mockHttpClient.EXPECT().
6565
Post("/agents/projects-assignments?organizationId="+organizationId, mapping, gomock.Any()).Times(1).Return(errorMock)
@@ -83,7 +83,7 @@ var _ = Describe("Agent Project Assignment", func() {
8383
var err error
8484

8585
BeforeEach(func() {
86-
mockOrganizationIdCall(organizationId).Times(1)
86+
mockOrganizationIdCall().Times(1)
8787

8888
httpCall = mockHttpClient.EXPECT().
8989
Get("/agents/projects-assignments", map[string]string{"organizationId": organizationId}, gomock.Any()).Times(1).
@@ -107,7 +107,7 @@ var _ = Describe("Agent Project Assignment", func() {
107107
var err error
108108

109109
BeforeEach(func() {
110-
mockOrganizationIdCall(organizationId).Times(1)
110+
mockOrganizationIdCall().Times(1)
111111

112112
httpCall = mockHttpClient.EXPECT().
113113
Get("/agents/projects-assignments", map[string]string{"organizationId": organizationId}, gomock.Any()).Times(1).

client/agent_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var _ = Describe("Agent Client", func() {
2424
var err error
2525

2626
BeforeEach(func() {
27-
mockOrganizationIdCall(organizationId)
27+
mockOrganizationIdCall()
2828

2929
httpCall = mockHttpClient.EXPECT().
3030
Get("/agents", gomock.Any(), gomock.Any()).
@@ -56,7 +56,7 @@ var _ = Describe("Agent Client", func() {
5656
var err error
5757

5858
BeforeEach(func() {
59-
mockOrganizationIdCall(organizationId)
59+
mockOrganizationIdCall()
6060

6161
httpCall = mockHttpClient.EXPECT().
6262
Get("/agents", gomock.Any(), gomock.Any()).

client/api_key_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var _ = Describe("ApiKey Client", func() {
2121
mockApiKeys := []ApiKey{mockApiKey}
2222

2323
BeforeEach(func() {
24-
mockOrganizationIdCall(organizationId)
24+
mockOrganizationIdCall()
2525
httpCall = mockHttpClient.EXPECT().
2626
Get("/api-keys", map[string]string{"organizationId": organizationId}, gomock.Any()).
2727
Do(func(path string, request interface{}, response *[]ApiKey) {
@@ -48,10 +48,11 @@ var _ = Describe("ApiKey Client", func() {
4848
var err error
4949

5050
BeforeEach(func() {
51-
mockOrganizationIdCall(organizationId)
51+
mockOrganizationIdCall()
5252

5353
createApiKeyPayload := ApiKeyCreatePayload{}
54-
copier.Copy(&createApiKeyPayload, &mockApiKey)
54+
55+
_ = copier.Copy(&createApiKeyPayload, &mockApiKey)
5556

5657
expectedCreateRequest := ApiKeyCreatePayloadWith{
5758
ApiKeyCreatePayload: createApiKeyPayload,
@@ -85,14 +86,20 @@ var _ = Describe("ApiKey Client", func() {
8586
})
8687

8788
Describe("Delete ApiKey", func() {
89+
var err error
90+
8891
BeforeEach(func() {
8992
httpCall = mockHttpClient.EXPECT().Delete("/api-keys/"+mockApiKey.Id, nil)
90-
apiClient.ApiKeyDelete(mockApiKey.Id)
93+
err = apiClient.ApiKeyDelete(mockApiKey.Id)
9194
})
9295

9396
It("Should send DELETE request with ApiKey id", func() {
9497
httpCall.Times(1)
9598
})
99+
100+
It("Should not return error", func() {
101+
Expect(err).To(BeNil())
102+
})
96103
})
97104

98105
Describe("Get Oidc Sub", func() {
@@ -101,7 +108,7 @@ var _ = Describe("ApiKey Client", func() {
101108
mockedOidcSub := "oidc sub 1234"
102109

103110
BeforeEach(func() {
104-
mockOrganizationIdCall(organizationId)
111+
mockOrganizationIdCall()
105112
httpCall = mockHttpClient.EXPECT().
106113
Get("/api-keys/oidc-sub", map[string]string{"organizationId": organizationId}, gomock.Any()).
107114
Do(func(path string, request interface{}, response *string) {

client/approval_policy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var _ = Describe("Approval Policy Client", func() {
3636
mockApprovalPolicies := []ApprovalPolicy{mockApprovalPolicy}
3737

3838
BeforeEach(func() {
39-
mockOrganizationIdCall(organizationId)
39+
mockOrganizationIdCall()
4040
httpCall = mockHttpClient.EXPECT().
4141
Get("/approval-policy", map[string]string{"organizationId": organizationId, "name": mockApprovalPolicy.Name}, gomock.Any()).
4242
Do(func(path string, request interface{}, response *[]ApprovalPolicy) {
@@ -125,10 +125,10 @@ var _ = Describe("Approval Policy Client", func() {
125125
var err error
126126

127127
BeforeEach(func() {
128-
mockOrganizationIdCall(organizationId).Times(1)
128+
mockOrganizationIdCall().Times(1)
129129

130130
createApprovalPolicyPayload := ApprovalPolicyCreatePayload{}
131-
copier.Copy(&createApprovalPolicyPayload, &mockApprovalPolicy)
131+
_ = copier.Copy(&createApprovalPolicyPayload, &mockApprovalPolicy)
132132

133133
expectedCreateRequest := struct {
134134
ApprovalPolicyCreatePayload
@@ -162,7 +162,7 @@ var _ = Describe("Approval Policy Client", func() {
162162

163163
BeforeEach(func() {
164164
updateApprovalPolicyPayload := ApprovalPolicyUpdatePayload{}
165-
copier.Copy(&updateApprovalPolicyPayload, &mockApprovalPolicy)
165+
_ = copier.Copy(&updateApprovalPolicyPayload, &mockApprovalPolicy)
166166

167167
httpCall = mockHttpClient.EXPECT().
168168
Put("/approval-policy", &updateApprovalPolicyPayload, gomock.Any()).

client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var _ = AfterSuite(func() {
3939
ctrl.Finish()
4040
})
4141

42-
func mockOrganizationIdCall(organizationId string) *gomock.Call {
42+
func mockOrganizationIdCall() *gomock.Call {
4343
organizations := []Organization{{
4444
Id: organizationId,
4545
}}

client/cloud_account_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var _ = Describe("CloudAccount", func() {
4747

4848
Describe("create", func() {
4949
BeforeEach(func() {
50-
mockOrganizationIdCall(organizationId)
50+
mockOrganizationIdCall()
5151

5252
payload := CloudAccountCreatePayload{
5353
Provider: account1.Provider,
@@ -151,7 +151,7 @@ var _ = Describe("CloudAccount", func() {
151151
}
152152

153153
BeforeEach(func() {
154-
mockOrganizationIdCall(organizationId)
154+
mockOrganizationIdCall()
155155

156156
httpCall = mockHttpClient.EXPECT().
157157
Get("/cloud/configurations", map[string]string{"organizationId": organizationId}, gomock.Any()).

client/cloud_credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func (client *ApiClient) CloudCredentialsList() ([]Credentials, error) {
152152
}
153153

154154
var credentials []Credentials
155-
err = client.http.Get("/credentials", map[string]string{"organizationId": organizationId}, &credentials)
156-
if err != nil {
155+
156+
if err := client.http.Get("/credentials", map[string]string{"organizationId": organizationId}, &credentials); err != nil {
157157
return []Credentials{}, err
158158
}
159159

client/cloud_credentials_project_assignment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ type CloudCredentialsProjectAssignment struct {
1313
func (client *ApiClient) AssignCloudCredentialsToProject(projectId string, credentialId string) (CloudCredentialsProjectAssignment, error) {
1414
var result CloudCredentialsProjectAssignment
1515

16-
err := client.http.Put("/credentials/deployment/"+credentialId+"/project/"+projectId, nil, &result)
17-
if err != nil {
16+
if err := client.http.Put("/credentials/deployment/"+credentialId+"/project/"+projectId, nil, &result); err != nil {
1817
return result, err
1918
}
19+
2020
return result, nil
2121
}
2222

@@ -26,10 +26,10 @@ func (client *ApiClient) RemoveCloudCredentialsFromProject(projectId string, cre
2626

2727
func (client *ApiClient) CloudCredentialIdsInProject(projectId string) ([]string, error) {
2828
var result CloudCredentialIdsInProjectResponse
29-
err := client.http.Get("/credentials/deployment/project/"+projectId, nil, &result)
3029

31-
if err != nil {
30+
if err := client.http.Get("/credentials/deployment/project/"+projectId, nil, &result); err != nil {
3231
return nil, err
3332
}
33+
3434
return result.CredentialIds, nil
3535
}

0 commit comments

Comments
 (0)