diff --git a/metadata/testdata/webapp.bin b/metadata/testdata/webapp.bin new file mode 100644 index 0000000..b2c26f3 Binary files /dev/null and b/metadata/testdata/webapp.bin differ diff --git a/metadata/web_app_test.go b/metadata/web_app_test.go index 3a668ef..84a3ea5 100644 --- a/metadata/web_app_test.go +++ b/metadata/web_app_test.go @@ -3,12 +3,19 @@ package metadata import ( "bytes" "encoding/json" + "fmt" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" + "github.com/vmihailenco/msgpack/v5" "testing" ) +func (wafr WebAppMetadataFileReference) Equal(other WebAppMetadataFileReference) bool { + return wafr.Cid.Equals(other.Cid) && wafr.ContentType == other.ContentType +} + func getWebappMeta() *WebAppMetadata { - data := getDirectoryMetaContent() + data := getWebappContent() var webapp WebAppMetadata @@ -26,6 +33,33 @@ func getWebappContent() []byte { return data } +func TestWebAppMetadata_DecodeJSON(t *testing.T) { + tests := []struct { + name string + wantErr bool + }{ + { + name: "Decode", + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + jsonDm := getWebappMeta() + dm := &WebAppMetadata{} + + if err := msgpack.Unmarshal(readFile("webapp.bin"), dm); (err != nil) != tt.wantErr { + t.Errorf("DecodeMsgpack() error = %v, wantErr %v", err, tt.wantErr) + } + + if !cmp.Equal(jsonDm, dm) { + fmt.Println(cmp.Diff(jsonDm, dm)) + t.Errorf("DecodeMsgpack() error = %v, wantErr %v", "msgpack does not match json", tt.wantErr) + } + }) + } +} + func TestWebAppMetadata_EncodeJSON(t *testing.T) { tests := []struct { name string