From a85f2f206d943820e80ce8d5287c5277c54e5816 Mon Sep 17 00:00:00 2001 From: Otto Bittner Date: Wed, 27 Nov 2024 09:28:45 +0100 Subject: [PATCH] add unittest for verify --- sdk/verify_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sdk/verify_test.go diff --git a/sdk/verify_test.go b/sdk/verify_test.go new file mode 100644 index 000000000..4ef3375b4 --- /dev/null +++ b/sdk/verify_test.go @@ -0,0 +1,39 @@ +package sdk + +import ( + "testing" +) + +func TestVerify(t *testing.T) { + tests := map[string]struct { + expectedManifest []byte + manifestHistory [][]byte + errMsg string + }{ + "Empty manifest history": { + expectedManifest: []byte("expected"), + manifestHistory: [][]byte{}, + errMsg: "manifest history is empty", + }, + "Matching manifest": { + expectedManifest: []byte("expected"), + manifestHistory: [][]byte{[]byte("old"), []byte("expected")}, + }, + "Non-matching manifest": { + expectedManifest: []byte("expected"), + manifestHistory: [][]byte{[]byte("old"), []byte("current")}, + errMsg: "active manifest does not match expected manifest", + }, + } + + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + client := Client{} + err := client.Verify(tt.expectedManifest, tt.manifestHistory) + + if err != nil && err.Error() != tt.errMsg { + t.Errorf("actual error: '%v', expected error: '%v'", err, tt.errMsg) + } + }) + } +}