-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
70 lines (58 loc) · 1.39 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"io"
"log"
"os"
"testing"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/spf13/viper"
"github.com/stretchr/testify/suite"
)
type cliTestSuite struct {
suite.Suite
viper *viper.Viper
logger *log.Logger
}
func (suite *cliTestSuite) Setup() {
// Disable any logging that isn't attached to the logger unless using the verbose flag
log.SetOutput(io.Discard)
log.SetFlags(0)
// Setup logger
var logger = log.New(os.Stdout, "", log.LstdFlags)
// Remove the flags for the logger
logger.SetFlags(0)
suite.SetLogger(logger)
// Setup viper
v := viper.New()
suite.SetViper(v)
}
func (suite *cliTestSuite) TestCheckRegion() {
suite.Setup()
testValues := []string{
endpoints.UsEast1RegionID,
endpoints.UsEast2RegionID,
endpoints.UsWest1RegionID,
endpoints.UsWest2RegionID,
endpoints.UsGovWest1RegionID,
}
for _, testValue := range testValues {
suite.viper.Set(flagAWSRegion, testValue)
suite.NoError(checkRegion(suite.viper))
}
testValuesWithErrors := []string{
"AnyOtherRegionName",
}
for _, testValue := range testValuesWithErrors {
suite.viper.Set(flagAWSRegion, testValue)
suite.Error(checkRegion(suite.viper))
}
}
func (suite *cliTestSuite) SetViper(v *viper.Viper) {
suite.viper = v
}
func (suite *cliTestSuite) SetLogger(logger *log.Logger) {
suite.logger = logger
}
func TestCLISuite(t *testing.T) {
suite.Run(t, &cliTestSuite{})
}