-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathcontext_test.go
More file actions
71 lines (58 loc) · 1.77 KB
/
context_test.go
File metadata and controls
71 lines (58 loc) · 1.77 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cmd_test
import (
"io/ioutil"
"log"
"os"
"os/exec"
"github.com/CircleCI-Public/circleci-cli/clitest"
"github.com/CircleCI-Public/circleci-cli/cmd"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("Context integration tests", func() {
Describe("when listing contexts without a token", func() {
var (
command *exec.Cmd
tempSettings *clitest.TempSettings
)
BeforeEach(func() {
tempSettings = clitest.WithTempSettings()
command = commandWithHome(pathCLI, tempSettings.Home,
"context", "list", "github", "foo",
"--skip-update-check",
"--token", "",
)
})
It("instructs the user to run 'circleci setup' and create a new token", func() {
By("running the command")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session.Err).Should(gbytes.Say(`Error: please set a token with 'circleci setup'
You can create a new personal API token here:
https://circleci.com/account/api`))
Eventually(session).Should(clitest.ShouldFail())
})
It("ReadSecretValue should read correctly os.Stdin wihout given a error", func() {
By("running the command")
content := []byte("stdin mock!")
tempFile, err := ioutil.TempFile("", "stdin-mock")
if err != nil {
log.Fatalln(err)
}
if _, err := tempFile.Write(content); err != nil {
log.Fatal(err)
}
if _, err := tempFile.Seek(0, 0); err != nil {
log.Fatal(err)
}
defer os.Remove(tempFile.Name())
os.Stdin = tempFile
result, err := cmd.ReadSecretValue()
Expect(err).ShouldNot(HaveOccurred())
Expect(result).Should(Equal(string(content)))
})
})
// TODO: add integration tests for happy path cases
})