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
|
diff --git a/cmd/spectre/main_test.go b/cmd/spectre/main_test.go
index 2f28f8d67d7252c848c46ab5882f7464e243bfc1..9c563e24c3e1f835cd7cdb789cebe0c07cd188e5 100644
--- a/cmd/spectre/main_test.go
+++ b/cmd/spectre/main_test.go
@@ -2,39 +2,29 @@ package main
import (
_ "embed"
- "encoding/xml"
- "fmt"
+ "go.jolheiser.com/go-spectre/testdata"
"testing"
)
// These are the exact same tests as spectre_test.go
// These are here just to make sure the CLI is giving the same outputs
func TestCLI(t *testing.T) {
- var tests TestCases
- if err := xml.Unmarshal(testsXML, &tests); err != nil {
- t.Log("could not load test data")
+ cases, err := testdata.Cases()
+ if err != nil {
+ t.Log(err)
t.FailNow()
}
- dc := tests.Cases[0]
- for _, tc := range tests.Cases[1:] {
+ for _, tc := range cases {
t.Run(tc.ID, func(t *testing.T) {
- user := def(dc.UserName, tc.UserName)
- secret := def(dc.UserSecret, tc.UserSecret)
- siteName := def(dc.SiteName, tc.SiteName)
- template := def(dc.ResultType, tc.ResultType)
- counter := def(dc.KeyCounter, tc.KeyCounter)
- scope := def(dc.KeyPurpose, tc.KeyPurpose)
-
args := []string{
- "--username", user,
- "--secret", secret,
- "--template", template,
- "--counter", counter,
- "--scope", scope,
- siteName,
+ "--username", tc.UserName,
+ "--secret", tc.UserSecret,
+ "--template", tc.ResultType,
+ "--counter", tc.KeyCounter,
+ "--scope", tc.KeyPurpose,
+ tc.SiteName,
}
- fmt.Println(args)
pw, err := doMain(args)
if err != nil {
@@ -49,28 +39,3 @@ }
})
}
}
-
-//go:embed spectre_tests.xml
-var testsXML []byte
-
-type TestCases struct {
- Cases []TestCase `xml:"case"`
-}
-
-type TestCase struct {
- ID string `xml:"id,attr"`
- UserName string `xml:"userName"`
- UserSecret string `xml:"userSecret"`
- SiteName string `xml:"siteName"`
- ResultType string `xml:"resultType"`
- KeyCounter string `xml:"keyCounter"`
- KeyPurpose string `xml:"keyPurpose"`
- Result string `xml:"result"`
-}
-
-func def(def, alt string) string {
- if alt != "" {
- return alt
- }
- return def
-}
|