aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/fs/hash_test.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/fs/hash_test.go
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'cli/internal/fs/hash_test.go')
-rw-r--r--cli/internal/fs/hash_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/cli/internal/fs/hash_test.go b/cli/internal/fs/hash_test.go
new file mode 100644
index 0000000..dd2fa84
--- /dev/null
+++ b/cli/internal/fs/hash_test.go
@@ -0,0 +1,53 @@
+package fs
+
+import (
+ "testing"
+
+ "gotest.tools/v3/assert"
+)
+
+const _numOfRuns = 20
+
+func Test_HashObjectStability(t *testing.T) {
+ type TestCase struct {
+ name string
+ obj interface{}
+ }
+ type complexStruct struct {
+ nested TaskOutputs
+ foo string
+ bar []string
+ }
+
+ testCases := []TestCase{
+ {
+ name: "task object",
+ obj: TaskOutputs{
+ Inclusions: []string{"foo", "bar"},
+ Exclusions: []string{"baz"},
+ },
+ },
+ {
+ name: "complex struct",
+ obj: complexStruct{
+ nested: TaskOutputs{
+ Exclusions: []string{"bar", "baz"},
+ Inclusions: []string{"foo"},
+ },
+ foo: "a",
+ bar: []string{"b", "c"},
+ },
+ },
+ }
+
+ for _, tc := range testCases {
+ expectedHash, err := HashObject(tc.obj)
+ assert.NilError(t, err, tc.name)
+
+ for n := 0; n < _numOfRuns; n++ {
+ hash, err := HashObject(tc.obj)
+ assert.NilError(t, err, tc.name)
+ assert.Equal(t, expectedHash, hash, tc.name)
+ }
+ }
+}