testing: add TestWebAppMetadata_DecodeJSON with test webapp.bin
This commit is contained in:
parent
6be36feabf
commit
01d695b175
Binary file not shown.
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue