testing: add TestWebAppMetadata_DecodeJSON with test webapp.bin

This commit is contained in:
Derrick Hammer 2024-01-18 12:09:34 -05:00
parent 6be36feabf
commit 01d695b175
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 35 additions and 1 deletions

BIN
metadata/testdata/webapp.bin vendored Normal file

Binary file not shown.

View File

@ -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