Skip to content

Commit

Permalink
Add golangci-lint for Go tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Dec 15, 2024
1 parent b8245f5 commit 10c6d65
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ indent_size = 2

[*.yml]
indent_size = 2

[*.go]
indent_style = tab
24 changes: 24 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: golangci-lint

on:
push:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
working-directory: go-tests
60 changes: 30 additions & 30 deletions go-tests/org_list_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package tests

import (
"net/http/httptest"
"net/url"
"strings"
"testing"
"net/http/httptest"
"net/url"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"

"github.com/platformsh/cli/pkg/mockapi"
"github.com/platformsh/cli/pkg/mockapi"
)

func TestOrgList(t *testing.T) {
authServer := mockapi.NewAuthServer(t)
defer authServer.Close()
authServer := mockapi.NewAuthServer(t)
defer authServer.Close()

myUserID := "user-id-1"
myUserID := "user-id-1"

apiHandler := mockapi.NewHandler(t)
apiHandler.SetMyUser(&mockapi.User{ID: myUserID})
apiHandler.SetOrgs([]*mockapi.Org{
makeOrg("org-id-1", "acme", "ACME Inc.", myUserID),
makeOrg("org-id-2", "four-seasons", "Four Seasons Total Landscaping", myUserID),
makeOrg("org-id-3", "duff", "Duff Beer", "user-id-2"),
})
apiHandler := mockapi.NewHandler(t)
apiHandler.SetMyUser(&mockapi.User{ID: myUserID})
apiHandler.SetOrgs([]*mockapi.Org{
makeOrg("org-id-1", "acme", "ACME Inc.", myUserID),
makeOrg("org-id-2", "four-seasons", "Four Seasons Total Landscaping", myUserID),
makeOrg("org-id-3", "duff", "Duff Beer", "user-id-2"),
})

apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

run := runnerWithAuth(t, apiServer.URL, authServer.URL)
run := runnerWithAuth(t, apiServer.URL, authServer.URL)

assert.Equal(t, strings.TrimLeft(`
assert.Equal(t, strings.TrimLeft(`
+--------------+--------------------------------+-----------------------+
| Name | Label | Owner email |
+--------------+--------------------------------+-----------------------+
Expand All @@ -40,27 +40,27 @@ func TestOrgList(t *testing.T) {
+--------------+--------------------------------+-----------------------+
`, "\n"), run("orgs"))

assert.Equal(t, strings.TrimLeft(`
assert.Equal(t, strings.TrimLeft(`
Name Label Owner email
acme ACME Inc. [email protected]
duff Duff Beer [email protected]
four-seasons Four Seasons Total Landscaping [email protected]
`, "\n"), run("orgs", "--format", "plain"))

assert.Equal(t, strings.TrimLeft(`
assert.Equal(t, strings.TrimLeft(`
org-id-1,acme
org-id-3,duff
org-id-2,four-seasons
`, "\n"), run("orgs", "--format", "csv", "--columns", "id,name", "--no-header"))
}

func makeOrg(id, name, label, owner string) *mockapi.Org {
return &mockapi.Org{
ID: id,
Name: name,
Label: label,
Owner: owner,
Capabilities: []string{},
Links: mockapi.MakeHALLinks("self=/organizations/" + url.PathEscape(id)),
}
return &mockapi.Org{
ID: id,
Name: name,
Label: label,
Owner: owner,
Capabilities: []string{},
Links: mockapi.MakeHALLinks("self=/organizations/" + url.PathEscape(id)),
}
}

0 comments on commit 10c6d65

Please sign in to comment.