-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix value processor. Cover with tests. (#14)
Fix value processor. Cover with tests.
- Loading branch information
1 parent
28e3457
commit 9ab631f
Showing
4 changed files
with
126 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
}) | ||
} | ||
} |