-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret_create_test.go
45 lines (41 loc) · 970 Bytes
/
secret_create_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 rove
import (
"os"
"slices"
"testing"
)
func TestSecretCreateCommand(t *testing.T) {
if err := testDatabase(func() error {
mock := &SshConnectionMock{Result: "fake-id\n"}
expectedCmd := []string{
"docker secret create --label 'rove=secret' foo foo.txt",
"rm foo.txt",
}
expected := "\nRove created the 'foo' secret with ID 'fake-id'.\n\n"
capture(t).
Run(func() error {
f, err := os.CreateTemp("", "foo.txt")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
defer f.Close()
if _, err := f.Write([]byte("fake-secret-content")); err != nil {
t.Fatal(err)
}
cmd := &SecretCreateCommand{
File: f,
Machine: "default",
Name: "foo",
}
return cmd.Do(mock, nil)
}).
ExpectStdout(expected)
if !slices.Equal(mock.CommandsRun, expectedCmd) {
t.Errorf("'%#v' did not match expected.", mock.CommandsRun)
}
return nil
}); err != nil {
t.Fatal(err)
}
}