A read-only clone of the dehub project, for until dehub.dev can be brought back online.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
dehub/yamlutil/yamlutil_test.go

55 lines
993 B

package yamlutil
import (
"bytes"
"testing"
yaml "gopkg.in/yaml.v2"
)
func TestBlob(t *testing.T) {
testCases := []struct {
descr string
in Blob
exp string
}{
{
descr: "empty",
in: Blob(""),
exp: `""`,
},
{
descr: "zero",
in: Blob{0},
exp: "AA==",
},
{
descr: "zeros",
in: Blob{0, 0, 0},
exp: "AAAA",
},
{
descr: "foo",
in: Blob("foo"),
exp: "Zm9v",
},
}
for _, test := range testCases {
t.Run(test.descr, func(t *testing.T) {
out, err := yaml.Marshal(test.in)
if err != nil {
t.Fatalf("error marshaling %q: %v", test.in, err)
} else if test.exp+"\n" != string(out) {
t.Fatalf("marshal exp:%q got:%q", test.exp+"\n", out)
}
var blob Blob
if err := yaml.Unmarshal(out, &blob); err != nil {
t.Fatalf("error unmarshaling %q: %v", out, err)
} else if !bytes.Equal([]byte(blob), []byte(test.in)) {
t.Fatalf("unmarshal exp:%q got:%q", test.in, blob)
}
})
}
}