Skip to content

Commit c622573

Browse files
authored
Merge pull request #192 from replicatedhq/kcboyle-cli-test-rework
CLI test update to ginkgo/v2 and test enable|disable-semantic versioning
2 parents 90b4c0f + db27566 commit c622573

27 files changed

+800
-520
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- uses: actions/checkout@v2
22+
- uses: actions/setup-go@v2
23+
with:
24+
go-version: '^1.17.4'
2225
- name: make test
2326
run: make test
2427
env:

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v2
21+
- uses: actions/setup-go@v2
22+
with:
23+
go-version: '^1.17.4'
2124
- name: make test
2225
run: make test
2326
env:
@@ -67,7 +70,7 @@ jobs:
6770
- name: Set up Go
6871
uses: actions/setup-go@v2
6972
with:
70-
go-version: 1.14
73+
go-version: 1.17
7174
- name: docker login
7275
run: docker login -u="$DOCKERHUB_DOCKER_USER" -p="$DOCKERHUB_DOCKER_PASS"
7376
env:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14
1+
FROM golang:1.17
22

33
ENV PROJECTPATH=/go/src/github.com/replicatedhq/replicated
44

cli/test/channel_adoption_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package test
22

33
import (
4-
"bufio"
54
"bytes"
65
"os"
76

8-
. "github.com/onsi/ginkgo"
9-
"github.com/stretchr/testify/assert"
10-
7+
. "github.com/onsi/ginkgo/v2"
8+
. "github.com/onsi/gomega"
119
"github.com/replicatedhq/replicated/cli/cmd"
1210
apps "github.com/replicatedhq/replicated/gen/go/v1"
1311
channels "github.com/replicatedhq/replicated/gen/go/v1"
@@ -17,19 +15,23 @@ import (
1715
// This only tests with no active licenses since the vendor API does not provide
1816
// a way to update licenses' last_active field.
1917
var _ = Describe("channel adoption", func() {
20-
api := platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
21-
t := GinkgoT()
22-
var app = &apps.App{Name: mustToken(8)}
23-
var appChan = &channels.AppChannel{}
18+
var (
19+
api *platformclient.HTTPClient
20+
app *apps.App
21+
appChan *channels.AppChannel
22+
err error
23+
)
2424

2525
BeforeEach(func() {
26-
t.Logf("%+v\n", api)
27-
var err error
26+
api = platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
27+
appChan = &channels.AppChannel{}
28+
app = &apps.App{Name: mustToken(8)}
29+
2830
app, err = api.CreateApp(&platformclient.AppOptions{Name: app.Name})
29-
assert.Nil(t, err)
31+
Expect(err).ToNot(HaveOccurred())
3032

3133
appChans, err := api.ListChannels(app.Id)
32-
assert.Nil(t, err)
34+
Expect(err).ToNot(HaveOccurred())
3335
appChan = &appChans[0]
3436
})
3537

@@ -46,15 +48,12 @@ var _ = Describe("channel adoption", func() {
4648
rootCmd := cmd.GetRootCmd()
4749
rootCmd.SetArgs([]string{"channel", "adoption", appChan.Id, "--app", app.Slug})
4850
err := cmd.Execute(rootCmd, nil, &stdout, &stderr)
49-
assert.Nil(t, err)
50-
51-
assert.Zero(t, stderr, "Expected no stderr output")
52-
assert.NotZero(t, stdout, "Expected stdout output")
51+
Expect(err).ToNot(HaveOccurred())
5352

54-
r := bufio.NewScanner(&stdout)
53+
Expect(stderr.String()).To(BeEmpty())
54+
Expect(stdout.String()).ToNot(BeEmpty())
5555

56-
assert.True(t, r.Scan())
57-
assert.Equal(t, "No active licenses in channel", r.Text())
56+
Expect(stdout.String()).To(Equal("No active licenses in channel\n"))
5857
})
5958
})
6059
})

cli/test/channel_counts_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
package test
22

33
import (
4-
"bufio"
54
"bytes"
65
"os"
76

8-
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/ginkgo/v2"
8+
. "github.com/onsi/gomega"
99
"github.com/replicatedhq/replicated/cli/cmd"
1010
apps "github.com/replicatedhq/replicated/gen/go/v1"
1111
channels "github.com/replicatedhq/replicated/gen/go/v1"
1212
"github.com/replicatedhq/replicated/pkg/platformclient"
13-
"github.com/stretchr/testify/assert"
1413
)
1514

1615
// This only tests with no active licenses since the vendor API does not provide
1716
// a way to update licenses' last_active field.
1817
var _ = Describe("channel counts", func() {
19-
api := platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
20-
t := GinkgoT()
21-
var app = &apps.App{Name: mustToken(8)}
22-
var appChan = &channels.AppChannel{}
18+
var (
19+
api *platformclient.HTTPClient
20+
app *apps.App
21+
appChan *channels.AppChannel
22+
err error
23+
)
2324

2425
BeforeEach(func() {
25-
var err error
26+
api = platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
27+
appChan = &channels.AppChannel{}
28+
app = &apps.App{Name: mustToken(8)}
29+
2630
app, err = api.CreateApp(&platformclient.AppOptions{Name: app.Name})
27-
assert.Nil(t, err)
31+
Expect(err).ToNot(HaveOccurred())
2832

2933
appChans, err := api.ListChannels(app.Id)
30-
assert.Nil(t, err)
34+
Expect(err).ToNot(HaveOccurred())
3135
appChan = &appChans[0]
3236
})
3337

@@ -45,15 +49,12 @@ var _ = Describe("channel counts", func() {
4549
rootCmd.SetArgs([]string{"channel", "counts", appChan.Id, "--app", app.Slug})
4650

4751
err := cmd.Execute(rootCmd, nil, &stdout, &stderr)
48-
assert.Nil(t, err)
49-
50-
assert.Zero(t, stderr, "Expected no stderr output")
51-
assert.NotZero(t, stdout, "Expected stdout output")
52+
Expect(err).ToNot(HaveOccurred())
5253

53-
r := bufio.NewScanner(&stdout)
54+
Expect(stderr.String()).To(BeEmpty())
55+
Expect(stdout.String()).ToNot(BeEmpty())
5456

55-
assert.True(t, r.Scan())
56-
assert.Equal(t, "No active licenses in channel", r.Text())
57+
Expect(stdout.String()).To(Equal("No active licenses in channel\n"))
5758
})
5859
})
5960
})

cli/test/channel_create_test.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,36 @@ import (
66
"fmt"
77
"os"
88

9-
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/ginkgo/v2"
10+
. "github.com/onsi/gomega"
1011
"github.com/replicatedhq/replicated/cli/cmd"
1112
apps "github.com/replicatedhq/replicated/gen/go/v1"
1213
"github.com/replicatedhq/replicated/pkg/platformclient"
13-
"github.com/stretchr/testify/assert"
1414
)
1515

1616
var _ = Describe("channel create", func() {
17-
api := platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
18-
t := GinkgoT()
19-
var app = &apps.App{Name: mustToken(8)}
17+
var (
18+
api *platformclient.HTTPClient
19+
app *apps.App
20+
name string
21+
desc string
22+
err error
23+
)
2024

2125
BeforeEach(func() {
22-
var err error
26+
api = platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
27+
app = &apps.App{Name: mustToken(8)}
28+
name = mustToken(8)
29+
desc = mustToken(16)
30+
2331
app, err = api.CreateApp(&platformclient.AppOptions{Name: app.Name})
24-
assert.Nil(GinkgoT(), err)
32+
Expect(err).ToNot(HaveOccurred())
2533
})
2634

2735
AfterEach(func() {
28-
// ignore error, garbage collection
2936
deleteApp(app.Id)
3037
})
3138

32-
name := mustToken(8)
33-
desc := mustToken(16)
3439
Describe(fmt.Sprintf("--name %s --description %s", name, desc), func() {
3540
It("should print the created channel", func() {
3641
var stdout bytes.Buffer
@@ -39,25 +44,24 @@ var _ = Describe("channel create", func() {
3944
rootCmd := cmd.GetRootCmd()
4045
rootCmd.SetArgs([]string{"channel", "create", "--name", name, "--description", desc, "--app", app.Slug})
4146
err := cmd.Execute(rootCmd, nil, &stdout, &stderr)
47+
Expect(err).ToNot(HaveOccurred())
4248

43-
assert.Nil(t, err)
44-
45-
assert.Empty(t, stderr.String(), "Expected no stderr output")
46-
assert.NotEmpty(t, stdout.String(), "Expected stdout output")
49+
Expect(stderr.String()).To(BeEmpty())
50+
Expect(stdout.String()).ToNot(BeEmpty())
4751

4852
r := bufio.NewScanner(&stdout)
4953

50-
assert.True(t, r.Scan())
51-
assert.Regexp(t, `^ID\s+NAME\s+RELEASE\s+VERSION$`, r.Text())
54+
Expect(r.Scan()).To(BeTrue())
55+
Expect(r.Text()).To(MatchRegexp(`^ID\s+NAME\s+RELEASE\s+VERSION$`))
5256

5357
// default Stable, Beta, and Unstable channels should be listed too
5458
for i := 0; i < 3; i++ {
55-
assert.True(t, r.Scan())
56-
assert.Regexp(t, `^\w+\s+\w+`, r.Text())
59+
Expect(r.Scan()).To(BeTrue())
60+
Expect(r.Text()).To(MatchRegexp(`^\w+\s+\w+`))
5761
}
5862

59-
assert.True(t, r.Scan())
60-
assert.Regexp(t, `^\w+\s+`+name+`\s+$`, r.Text())
63+
Expect(r.Scan()).To(BeTrue())
64+
Expect(r.Text()).To(MatchRegexp(`^\w+\s+` + name + `\s+$`))
6165
})
6266
})
6367
})

cli/test/channel_inspect_test.go

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@ package test
33
import (
44
"bufio"
55
"bytes"
6-
"os"
7-
8-
. "github.com/onsi/ginkgo"
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
98
"github.com/replicatedhq/replicated/cli/cmd"
109
apps "github.com/replicatedhq/replicated/gen/go/v1"
1110
channels "github.com/replicatedhq/replicated/gen/go/v1"
1211
"github.com/replicatedhq/replicated/pkg/platformclient"
13-
"github.com/stretchr/testify/assert"
12+
"os"
1413
)
1514

1615
var _ = Describe("channel inspect", func() {
17-
api := platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
18-
t := GinkgoT()
19-
var app = &apps.App{Name: mustToken(8)}
20-
var appChan = &channels.AppChannel{}
16+
var (
17+
api *platformclient.HTTPClient
18+
app *apps.App
19+
appChan *channels.AppChannel
20+
err error
21+
)
2122

2223
BeforeEach(func() {
23-
var err error
24+
api = platformclient.NewHTTPClient(os.Getenv("REPLICATED_API_ORIGIN"), os.Getenv("REPLICATED_API_TOKEN"))
25+
app = &apps.App{Name: mustToken(8)}
26+
appChan = &channels.AppChannel{}
27+
2428
app, err = api.CreateApp(&platformclient.AppOptions{Name: app.Name})
25-
assert.Nil(t, err)
29+
Expect(err).ToNot(HaveOccurred())
2630

2731
appChans, err := api.ListChannels(app.Id)
28-
assert.Nil(t, err)
32+
Expect(err).ToNot(HaveOccurred())
2933
appChan = &appChans[0]
3034
})
3135

@@ -43,40 +47,27 @@ var _ = Describe("channel inspect", func() {
4347
rootCmd.SetArgs([]string{"channel", "inspect", appChan.Id, "--app", app.Slug})
4448

4549
err := cmd.Execute(rootCmd, nil, &stdout, &stderr)
46-
assert.Nil(t, err)
50+
Expect(err).ToNot(HaveOccurred())
4751

48-
assert.Zero(t, stderr, "Expected no stderr output")
49-
assert.NotZero(t, stdout, "Expected stdout output")
52+
Expect(stderr.String()).To(BeEmpty())
53+
Expect(stdout.String()).ToNot(BeEmpty())
5054

5155
r := bufio.NewScanner(&stdout)
5256

53-
assert.True(t, r.Scan())
54-
assert.Regexp(t, `^ID:\s+`+appChan.Id+`$`, r.Text())
55-
56-
assert.True(t, r.Scan())
57-
assert.Regexp(t, `^NAME:\s+`+appChan.Name+`$`, r.Text())
58-
59-
assert.True(t, r.Scan())
60-
assert.Regexp(t, `^DESCRIPTION:\s+`+appChan.Description+`$`, r.Text())
61-
62-
assert.True(t, r.Scan())
63-
assert.Regexp(t, `^RELEASE:\s+`, r.Text())
64-
/*
65-
assert.True(t, r.Scan())
66-
assert.Equal(t, "LICENSE_COUNTS", r.Text())
57+
Expect(r.Scan()).To(BeTrue())
58+
Expect(r.Text()).To(MatchRegexp(`^ID:\s+` + appChan.Id + `$`))
6759

68-
assert.True(t, r.Scan())
69-
assert.Equal(t, "No licenses in channel", r.Text())
60+
Expect(r.Scan()).To(BeTrue())
61+
Expect(r.Text()).To(MatchRegexp(`^NAME:\s+` + appChan.Name + `$`))
7062

71-
assert.True(t, r.Scan())
72-
assert.Equal(t, "", r.Text())
63+
Expect(r.Scan()).To(BeTrue())
64+
Expect(r.Text()).To(MatchRegexp(`^DESCRIPTION:\s+` + appChan.Description + `$`))
7365

74-
assert.True(t, r.Scan())
75-
assert.Equal(t, "RELEASES", r.Text())
66+
Expect(r.Scan()).To(BeTrue())
67+
Expect(r.Text()).To(MatchRegexp(`^RELEASE:\s+`))
7668

77-
assert.True(t, r.Scan())
78-
assert.Equal(t, "No releases in channel", r.Text())
79-
*/
69+
Expect(r.Scan()).To(BeTrue())
70+
Expect(r.Text()).To(MatchRegexp(`^VERSION:\s+`))
8071
})
8172
})
8273
})

0 commit comments

Comments
 (0)