forked from getsavvyinc/savvy-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparam_test.go
56 lines (51 loc) · 1.18 KB
/
param_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
package param_test
import (
"reflect"
"testing"
"github.com/getsavvyinc/savvy-cli/param"
)
func TestExtractParams(t *testing.T) {
testCases := []struct {
name string
input string
expected []string
}{
{
name: "no params",
input: "No parameters here!",
},
{
name: "param with alphabets",
input: `jobrunner.sh --file="<file>"`,
expected: []string{"<file>"},
},
{
name: "param with numbers",
input: `script --id="<id1>" --name="<name2>"`,
expected: []string{"<id1>", "<name2>"},
},
{
name: "incomplete param",
input: "Edge case with incomplete <param and another<param2>",
expected: []string{"<param2>"},
},
{
name: "param with hyphen, underscore",
input: `script --id="<id-1>" --name="<name_2>"`,
expected: []string{"<id-1>", "<name_2>"},
},
{
name: "dedupe params",
input: `script --id="<id-1>" --name="<id-1>"`,
expected: []string{"<id-1>"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual := param.Extract(tc.input)
if !reflect.DeepEqual(actual, tc.expected) {
t.Errorf("expected %v; got %v", tc.expected, actual)
}
})
}
}