-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils_test.go
More file actions
48 lines (40 loc) · 1.32 KB
/
utils_test.go
File metadata and controls
48 lines (40 loc) · 1.32 KB
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
package commands
import (
"bytes"
"os"
"testing"
drycc "github.com/drycc/controller-sdk-go"
"github.com/stretchr/testify/assert"
)
func TestDrinkOfChoice(t *testing.T) {
os.Setenv("DRYCC_DRINK_OF_CHOICE", "test")
assert.Equal(t, drinkOfChoice(), "test", "output")
os.Unsetenv("DRYCC_DRINK_OF_CHOICE")
assert.Equal(t, drinkOfChoice(), "coffee", "output")
}
func TestLimitsCount(t *testing.T) {
t.Parallel()
assert.Equal(t, limitCount(1, 1), "\n", "output")
assert.Equal(t, limitCount(1, 2), " (1 of 2)\n", "output")
}
func TestAPICompatibility(t *testing.T) {
t.Parallel()
var b bytes.Buffer
cmdr := DryccCmd{WErr: &b, ConfigFile: ""}
client := drycc.Client{ControllerAPIVersion: "v1.0"}
err := cmdr.checkAPICompatibility(&client, drycc.ErrAPIMismatch)
assert.NoError(t, err)
assert.Equal(t, b.String(), `! WARNING: Client and server API versions do not match. Please consider upgrading.
! Client version: 2.3
! Server version: v1.0
`, "output")
// After being warned once, the warning should not be printed again.
b.Reset()
err = cmdr.checkAPICompatibility(&client, drycc.ErrAPIMismatch)
assert.NoError(t, err)
assert.Equal(t, b.String(), "", "output")
b.Reset()
err = cmdr.checkAPICompatibility(&client, drycc.ErrConflict)
assert.Error(t, drycc.ErrConflict, err)
assert.Equal(t, b.String(), "", "output")
}