Skip to content

Commit e582a1d

Browse files
author
Chris Gilmer
committed
Use suite for common code
1 parent 87dc582 commit e582a1d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

cmd/common_test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66
"testing"
77

8-
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/suite"
99
)
1010

1111
func newConfigFile(t *testing.T, b []byte) string {
@@ -19,27 +19,35 @@ func newConfigFile(t *testing.T, b []byte) string {
1919
return f.Name()
2020
}
2121

22-
func TestGenerateQrCode(t *testing.T) {
22+
type commonTestSuite struct {
23+
suite.Suite
24+
}
25+
26+
func TestCommonSuite(t *testing.T) {
27+
suite.Run(t, &commonTestSuite{})
28+
}
29+
30+
func (suite *commonTestSuite) TestGenerateQrCode() {
2331
tempFile, err := ioutil.TempFile("", "temp-qr.*.png")
24-
assert.NoError(t, err)
32+
suite.NoError(err)
2533
defer func() {
2634
errRemove := os.Remove(tempFile.Name())
27-
assert.NoError(t, errRemove)
35+
suite.NoError(errRemove)
2836
}()
2937

3038
err = generateQrCode("otpauth://totp/super@top?secret=secret", tempFile)
31-
assert.NoError(t, err)
39+
suite.NoError(err)
3240
}
3341

34-
func TestGetPartition(t *testing.T) {
42+
func (suite *commonTestSuite) TestGetPartition() {
3543
commPartition, err := getPartition("us-west-2")
36-
assert.Equal(t, commPartition, "aws")
37-
assert.NoError(t, err)
44+
suite.Equal(commPartition, "aws")
45+
suite.NoError(err)
3846

3947
govPartition, err := getPartition("us-gov-west-1")
40-
assert.Equal(t, govPartition, "aws-us-gov")
41-
assert.NoError(t, err)
48+
suite.Equal(govPartition, "aws-us-gov")
49+
suite.NoError(err)
4250

4351
_, err = getPartition("aws-under-the-sea")
44-
assert.Error(t, err)
52+
suite.Error(err)
4553
}

0 commit comments

Comments
 (0)