-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.go
45 lines (39 loc) · 1.02 KB
/
cli_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
package weather_test
import (
"os"
"testing"
"github.com/aculclasure/weather"
)
func TestCurrentWeatherCLI(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
apiKey string
args []string
errExpected bool
}{
"missing OPENWEATHER_API_KEY environment variable returns an error": {
apiKey: "",
errExpected: true,
},
"missing weather location positional argument returns an error": {
apiKey: "KEY",
args: []string{"weathercli", "--units=imperial"},
errExpected: true,
},
"missing value for units flag returns an error": {
apiKey: "KEY",
args: []string{"weathercli", "--units=", "London"},
errExpected: true,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
os.Setenv("OPENWEATHER_API_KEY", tc.apiKey)
err := weather.CurrentWeatherCLI(tc.args)
errReceived := err != nil
if tc.errExpected != errReceived {
t.Fatalf("CLI(%+v) returned unexpected error status: %v", tc.args, errReceived)
}
})
}
}