-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin_test.go
80 lines (71 loc) · 1.87 KB
/
plugin_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
package keyring
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/launchrctl/launchr/pkg/action"
)
const testActionYaml = `
runtime: plugin
action:
title: test keyring
options:
- name: secret
process:
- processor: keyring.GetKeyValue
options:
key: storedsecret
`
const testActionYamlWithDefault = `
runtime: plugin
action:
title: test keyring
options:
- name: secret
default: "mydefault"
process:
- processor: keyring.GetKeyValue
options:
key: storedsecret
`
const testActionYamlWrongOptions = `
runtime: plugin
action:
title: test keyring
options:
- name: secret
process:
- processor: keyring.GetKeyValue
`
func Test_KeyringProcessor(t *testing.T) {
// Prepare services.
k := &keyringService{
store: &dataStoreYaml{file: &plainFile{fname: "teststorage.yaml"}},
}
am := action.NewManager()
addValueProcessors(am, k)
// Prepare test data.
expected := "my_secret"
err := k.AddItem(KeyValueItem{Key: "storedsecret", Value: expected})
require.NoError(t, err)
expConfig := action.InputParams{
"secret": expected,
}
expGiven := action.InputParams{
"secret": "my_user_secret",
}
errOpts := fmt.Errorf("option %q is required for %q processor", "key", procGetKeyValue)
tt := []action.TestCaseValueProcessor{
{Name: "get keyring keyvalue - no input given", Yaml: testActionYaml, ExpOpts: expConfig},
{Name: "get keyring keyvalue - default and no input given", Yaml: testActionYamlWithDefault, ExpOpts: expConfig},
{Name: "get keyring keyvalue - input given", Yaml: testActionYaml, Opts: expGiven, ExpOpts: expGiven},
{Name: "get keyring keyvalue - wrong options", Yaml: testActionYamlWrongOptions, ErrInit: errOpts},
}
for _, tt := range tt {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
tt.Test(t, am)
})
}
}