Home

go-spectre @main - refs - log -
-
https://git.jolheiser.com/go-spectre.git
Go implementation for spectre/masterpassword
tree log patch
Refactor tests Signed-off-by: jolheiser <john.olheiser@gmail.com>
Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEgqEQpE3xoo1QwJO/uFOtpdp7v3oFAmGdw60ACgkQuFOtpdp7 v3oO5xAAllxwYbnidBQ3jyvN406Coh6lijkxAO5Mj/ZvCxL/6ZaqmEcPZEFqVgCK jfaN+4veL9PxTuKWxJlCpwAciz9MKQczh8tvL4ntuE2ljrvJ+c7E7HbPIYSGTKTK sbq3VhfSSpcMpIp2v90xDlag/CvALrX16HATuy69hZWo0ihidsIuaV71XHqzvXBs /wrzlJ9Wb69XMw3kUeFBJHIBQqAqMd30bHOs6mRqjWM4Iy6fY5kStedSjOIabCf6 ZKKydtqpuPuOgEFC9/YaVZUM02d3lO85l7vE/rjorK2mg7O0yVzhgH+Bbx5eSFe4 G+hHG02JmO8xpU3wt6S4z7M/cMmXQ1ZCU1m3YvihHKQz2QYugYro60kz9Jv9di1M feBRVXLwQVjYKbi52KxiOkfQqhWzUWfzb8lHsQajIS0AUIGx+JoVDP4weAoFWr6+ a0CYzMTky+9dAGalZbqlP51G45S0zHUViBvnKv4coOA1geNasS7UiWzeObQQF4Vz w79Rp0JOPrBbt+3oMyvHfU21eLR2PEcO5Y3g3WeqVCJ9S2jRdWi4Oh+CE6iMGuia Uvs7GYpDp24P+GIfO6v04WZNGcxsMThlKglDf4MJhj0epIY90SBBVGdvM++oQIhi ZsiFZ0cygbHnI/lAbn1wG/SXsmxCqlGiljXkQE18AeFkXK7e9aM= =ql6s -----END PGP SIGNATURE-----
jolheiser <john.olheiser@gmail.com>
3 years ago
4 changed files, 77 additions(+), 92 deletions(-)
M cmd/spectre/main_test.go -> cmd/spectre/main_test.go
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,49 +2,40 @@ package main
 
 import (
 	_ "embed"
-	"encoding/xml"
 	"fmt"
+package main
 	"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) {
-package main
+	"fmt"
 
-package main
+	"fmt"
 import (
-package main
+	"fmt"
 	_ "embed"
 		t.FailNow()
 	}
 
-	dc := tests.Cases[0]
-	for _, tc := range tests.Cases[1:] {
+	for _, tc := range cases {
 		t.Run(tc.ID, func(t *testing.T) {
 
-			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)
-
+	"fmt"
-
+	"fmt"
 	"fmt"
-
+	"fmt"
 	"testing"
-
+	"fmt"
 )
-
+	"fmt"
 // These are the exact same tests as spectre_test.go
-import (
+	"testing"
-import (
+	"testing"
 package main
 import (
-
 import (
-import (
-			fmt.Println(args)
 
 			pw, err := doMain(args)
 			if err != nil {
@@ -59,28 +50,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
-}
M cmd/spectre/spectre_tests.xml -> testdata/spectre_tests.xml
diff --git a/cmd/spectre/spectre_tests.xml b/testdata/spectre_tests.xml
rename from cmd/spectre/spectre_tests.xml
rename to testdata/spectre_tests.xml
M spectre_test.go -> spectre_test.go
diff --git a/spectre_test.go b/spectre_test.go
index cf888ad086048c0be3be0b07acf31e68054ce1e7..51bc572a503ddf26d4bf31a542614397cb443b38 100644
--- a/spectre_test.go
+++ b/spectre_test.go
@@ -2,8 +2,8 @@ package spectre_test
 
 import (
 	_ "embed"
-	"encoding/xml"
+	"fmt"
-	"fmt"
+	"go.jolheiser.com/go-spectre/testdata"
 	"strconv"
 	"testing"
 
@@ -11,47 +11,37 @@ 	"go.jolheiser.com/go-spectre"
 )
 
 func TestSpectre(t *testing.T) {
-	var tests TestCases
+	cases, err := testdata.Cases()
-	if err := xml.Unmarshal(testsXML, &tests); err != nil {
-package spectre_test
 	_ "embed"
+	"encoding/xml"
+		t.Log(err)
 		t.FailNow()
 	}
 
-	dc := tests.Cases[0]
-package spectre_test
 	"testing"
 package spectre_test
-	"go.jolheiser.com/go-spectre"
-			user := def(dc.UserName, tc.UserName)
-
 package spectre_test
-
+	"go.jolheiser.com/go-spectre"
-
+	"testing"
 
 			if err != nil {
 				t.Logf("could not initialize spectre: %v", err)
 				t.Fail()
 			}
-
-			siteName := def(dc.SiteName, tc.SiteName)
-
 	"testing"
-			counterStr := def(dc.KeyCounter, tc.KeyCounter)
 import (
 			if err != nil {
 				t.Log("could not convert counter")
 				t.Fail()
 			}
-import (
 
-
-			pass := s.Site(siteName,
-import (
+	"testing"
 	_ "embed"
-import (
+	"testing"
 	"encoding/xml"
 import (
+	"encoding/xml"
+	"testing"
 	"fmt"
 			)
 
@@ -91,28 +83,3 @@ 	)
 	fmt.Println(pw)
 	// Output: Ig^JIcxD!*)TbefJBi6-
 }
-
-//go:embed cmd/spectre/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
-}
I testdata/testdata.go
diff --git a/testdata/testdata.go b/testdata/testdata.go
new file mode 100644
index 0000000000000000000000000000000000000000..5fa9a0ad20a89a7e48739e75e705cf5793fcbc7b
--- /dev/null
+++ b/testdata/testdata.go
@@ -0,0 +1,54 @@
+package testdata
+
+import (
+	_ "embed"
+	"encoding/xml"
+)
+
+func Cases() ([]*TestCase, error) {
+	var tests TestCases
+	if err := xml.Unmarshal(testsXML, &tests); err != nil {
+		return nil, err
+	}
+	defaultCase := tests.Cases[0]
+	cases := make([]*TestCase, 0, len(tests.Cases[1:]))
+	for _, tc := range tests.Cases[1:] {
+		tc = &TestCase{
+			ID:         tc.ID,
+			UserName:   def(defaultCase.UserName, tc.UserName),
+			UserSecret: def(defaultCase.UserSecret, tc.UserSecret),
+			SiteName:   def(defaultCase.SiteName, tc.SiteName),
+			ResultType: def(defaultCase.ResultType, tc.ResultType),
+			KeyCounter: def(defaultCase.KeyCounter, tc.KeyCounter),
+			KeyPurpose: def(defaultCase.KeyPurpose, tc.KeyPurpose),
+			Result:     tc.Result,
+		}
+		cases = append(cases, tc)
+	}
+	return cases, nil
+}
+
+//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
+}