forked from 1Password/shell-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
credentials_test.go
100 lines (90 loc) · 3.59 KB
/
credentials_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
91
92
93
94
95
96
97
98
99
100
package ngrok
import (
"testing"
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/plugintest"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
"github.com/stretchr/testify/assert"
)
func TestCredentialsProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, ngrokProvisioner(), map[string]plugintest.ProvisionCase{
"temp file": {
ItemFields: map[sdk.FieldName]string{
fieldname.Authtoken: "uSuQ7LUOJLs4xRbIySZ15F4v5KxfTnMknMdFEXAMPLE",
fieldname.APIKey: "L4STpMP3K8FNaQjBo5EAsXA2SThzq0J7BKD3jUZgtEXAMPLE",
},
CommandLine: []string{"ngrok"},
ExpectedOutput: sdk.ProvisionOutput{
CommandLine: []string{"ngrok", "--config=/tmp/config.yml"},
Files: map[string]sdk.OutputFile{
"/tmp/config.yml": {
Contents: []byte(plugintest.LoadFixture(t, "config.yml")),
},
},
},
},
})
}
func TestCredentialsImporter(t *testing.T) {
plugintest.TestImporter(t, Credentials().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"NGROK_AUTHTOKEN": "uSuQ7LUOJLs4xRbIySZ15F4v5KxfTnMknMdFEXAMPLE",
"NGROK_API_KEY": "L4STpMP3K8FNaQjBo5EAsXA2SThzq0J7BKD3jUZgtEXAMPLE",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Authtoken: "uSuQ7LUOJLs4xRbIySZ15F4v5KxfTnMknMdFEXAMPLE",
fieldname.APIKey: "L4STpMP3K8FNaQjBo5EAsXA2SThzq0J7BKD3jUZgtEXAMPLE",
},
},
},
},
"config file for macos": {
OS: "darwin",
Files: map[string]string{
"~/Library/Application Support/ngrok/ngrok.yml": plugintest.LoadFixture(t, "config.yml"),
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Authtoken: "uSuQ7LUOJLs4xRbIySZ15F4v5KxfTnMknMdFEXAMPLE",
fieldname.APIKey: "L4STpMP3K8FNaQjBo5EAsXA2SThzq0J7BKD3jUZgtEXAMPLE",
},
},
},
},
"config file for linux": {
OS: "linux",
Files: map[string]string{
"~/.config/ngrok/ngrok.yml": plugintest.LoadFixture(t, "config.yml"),
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Authtoken: "uSuQ7LUOJLs4xRbIySZ15F4v5KxfTnMknMdFEXAMPLE",
fieldname.APIKey: "L4STpMP3K8FNaQjBo5EAsXA2SThzq0J7BKD3jUZgtEXAMPLE",
},
},
},
},
})
}
func TestGetAndReplaceConfigFlag(t *testing.T) {
config, args := getConfigValueAndNewArgs([]string{}, "/newPath/to/newFile.json")
assert.Equal(t, "", config)
assert.Equal(t, []string{"--config=/newPath/to/newFile.json"}, args)
config, args = getConfigValueAndNewArgs([]string{"--cache", "false", "--session", "asdefg345reger"}, "/newPath/to/newFile.json")
assert.Equal(t, "", config)
assert.Equal(t, []string{"--cache", "false", "--session", "asdefg345reger", "--config=/newPath/to/newFile.json"}, args)
config, args = getConfigValueAndNewArgs([]string{"--cache", "false", "--config"}, "/newPath/to/newFile.json")
assert.Equal(t, "", config)
assert.Equal(t, []string{"--cache", "false", "--config", "/newPath/to/newFile.json"}, args)
config, args = getConfigValueAndNewArgs([]string{"--cache", "false", "--config", "/path/to/file.json"}, "/newPath/to/newFile.json")
assert.Equal(t, "/path/to/file.json", config)
assert.Equal(t, []string{"--cache", "false", "--config", "/newPath/to/newFile.json"}, args)
config, args = getConfigValueAndNewArgs([]string{"--config=/path/to/file.json", "--session", "asdefg345reger"}, "/newPath/to/newFile.json")
assert.Equal(t, "/path/to/file.json", config)
assert.Equal(t, []string{"--config=/newPath/to/newFile.json", "--session", "asdefg345reger"}, args)
}