Skip to content

Commit bb3b8a6

Browse files
Add integration test for new remove auth command (#987)
* Add integration test for #981 * fix expected string per feedback Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
1 parent d99d665 commit bb3b8a6

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// +build !windows
2+
3+
package integration
4+
5+
import (
6+
"io/ioutil"
7+
"os/exec"
8+
"path/filepath"
9+
"testing"
10+
11+
"github.com/sclevine/spec"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
var _ = suite("auth/remove", func(t *testing.T, when spec.G, it spec.S) {
16+
var (
17+
expect *require.Assertions
18+
tmpDir string
19+
testConfig string
20+
)
21+
22+
it.Before(func() {
23+
expect = require.New(t)
24+
25+
var err error
26+
tmpDir, err = ioutil.TempDir("", "")
27+
expect.NoError(err)
28+
29+
testConfig = filepath.Join(tmpDir, "test-config.yml")
30+
var testConfigBytes = []byte(`access-token: first-token
31+
auth-contexts:
32+
second: second-token
33+
context: default
34+
`)
35+
36+
expect.NoError(ioutil.WriteFile(testConfig, testConfigBytes, 0644))
37+
38+
})
39+
40+
when("a context is not provided", func() {
41+
it("should error", func() {
42+
43+
cmd := exec.Command(builtBinaryPath,
44+
"auth",
45+
"remove",
46+
"--config", testConfig,
47+
)
48+
output, err := cmd.CombinedOutput()
49+
expect.Error(err)
50+
51+
expect.Equal("Error: You must provide a context name\n", string(output[:]))
52+
})
53+
})
54+
55+
when("a valid context is provided", func() {
56+
it("allows you to remove that context", func() {
57+
removeContext := "second"
58+
59+
cmd := exec.Command(builtBinaryPath,
60+
"auth",
61+
"remove",
62+
"--config", testConfig,
63+
"--context",
64+
removeContext,
65+
)
66+
_, err := cmd.CombinedOutput()
67+
expect.NoError(err)
68+
69+
fileBytes, err := ioutil.ReadFile(testConfig)
70+
expect.NoError(err)
71+
expect.NotContains(string(fileBytes), "second-token")
72+
})
73+
})
74+
})

0 commit comments

Comments
 (0)