5
5
"os"
6
6
"testing"
7
7
8
- "github.com/stretchr/testify/assert "
8
+ "github.com/stretchr/testify/suite "
9
9
)
10
10
11
11
func newConfigFile (t * testing.T , b []byte ) string {
@@ -19,27 +19,35 @@ func newConfigFile(t *testing.T, b []byte) string {
19
19
return f .Name ()
20
20
}
21
21
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 () {
23
31
tempFile , err := ioutil .TempFile ("" , "temp-qr.*.png" )
24
- assert .NoError (t , err )
32
+ suite .NoError (err )
25
33
defer func () {
26
34
errRemove := os .Remove (tempFile .Name ())
27
- assert .NoError (t , errRemove )
35
+ suite .NoError (errRemove )
28
36
}()
29
37
30
38
err = generateQrCode ("otpauth://totp/super@top?secret=secret" , tempFile )
31
- assert .NoError (t , err )
39
+ suite .NoError (err )
32
40
}
33
41
34
- func TestGetPartition ( t * testing. T ) {
42
+ func ( suite * commonTestSuite ) TestGetPartition ( ) {
35
43
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 )
38
46
39
47
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 )
42
50
43
51
_ , err = getPartition ("aws-under-the-sea" )
44
- assert .Error (t , err )
52
+ suite .Error (err )
45
53
}
0 commit comments