-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunner_test.go
90 lines (72 loc) · 1.51 KB
/
runner_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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
type MockProvider struct {
GenericProvider
}
func (m *MockProvider) Name() string {
return "mock"
}
func (m *MockProvider) Init(_ map[string]string) error {
return nil
}
func (m *MockProvider) ListSecrets(project string, prefix string) ([]*SecretData, error) {
return []*SecretData{
&SecretData{
Path: "/project/123/secrets/mysecret",
Name: "mysecret",
Data: "s3cr3t",
},
}, nil
}
func TestUnsupportedProvider(t *testing.T) {
opts := &Options{
Provider: "unsupported",
Project: "my-project",
Parser: "json",
}
err := Run(opts)
assert.Equal(t, ErrUnsupportedProvider, err)
}
func TestUnsupportedParser(t *testing.T) {
opts := &Options{
Provider: "gcp",
Project: "my-project",
Parser: "unsupported",
}
err := Run(opts)
assert.Equal(t, ErrUnsupportedParser, err)
}
func TestGCPProjectNotFound(t *testing.T) {
opts := &Options{Provider: "gcp"}
err := Run(opts)
assert.Equal(t, ErrProjectNotFound, err)
}
func TestHappyPath(t *testing.T) {
providers["mock"] = &MockProvider{}
file, err := os.CreateTemp("", "test")
if err != nil {
panic(err)
}
defer os.Remove(file.Name())
opts := &Options{
Provider: "mock",
Project: "my-project",
Parser: "plaintext",
Output: file.Name(),
}
err = Run(opts)
if err != nil {
panic(err)
}
content, err := os.ReadFile(file.Name())
if err != nil {
panic(err)
}
expected := `
export MYSECRET="s3cr3t"`
assert.Equal(t, expected, string(content))
}