gokwallet/blob_funcs_test.go

56 lines
1.5 KiB
Go
Raw Normal View History

package gokwallet
2021-12-25 02:54:18 -05:00
import (
2021-12-28 02:50:54 -05:00
"bytes"
2021-12-25 02:54:18 -05:00
"testing"
)
2021-12-28 02:50:54 -05:00
// TestBlob tests all functions of a Blob.
func TestBlob(t *testing.T) {
2021-12-25 02:54:18 -05:00
var b *Blob
2021-12-28 02:50:54 -05:00
var e *testEnv
var err error
var i int
2021-12-25 02:54:18 -05:00
2021-12-28 02:50:54 -05:00
if e, err = getTestEnv(t); err != nil {
2021-12-25 02:54:18 -05:00
t.Fatalf("failure getting test env: %v", err)
}
2021-12-28 02:50:54 -05:00
defer e.cleanup(t)
if b, err = NewBlob(e.f, blobTest.String(), e.r); err != nil {
t.Fatalf("failure getting Blob: %v", err)
}
t.Logf("created Blob '%v:%v:%v'; initialized: %v", e.w.Name, e.f.Name, b.Name, b.isInit)
if err = b.SetValue(testBytes); err != nil {
t.Errorf("failed to set value for Blob '%v:%v:%v': %v", e.w.Name, e.f.Name, b.Name, err)
}
if i = bytes.Compare(b.Value, testBytes); i != 0 {
t.Errorf("value '%#v' does not match expected value '%#v'", b.Value, testBytes)
} else {
t.Logf("value for Blob '%v:%v:%v': %#v", e.w.Name, e.f.Name, b.Name, b.Value)
}
if err = b.SetValue(testBytesReplace); err != nil {
t.Errorf("failed to set replacement value for Blob '%v:%v:%v': %v", e.w.Name, e.f.Name, b.Name, err)
}
if err = b.Update(); err != nil {
t.Errorf("failed to update Blob '%v:%v:%v': %v", e.w.Name, e.f.Name, b.Name, err)
}
t.Logf("replacement value for Blob '%v:%v:%v': %v", e.w.Name, e.f.Name, b.Name, b.Value)
if i = bytes.Compare(b.Value, testBytesReplace); i != 0 {
t.Errorf("value '%#v' does not match expected value '%#v'", b.Value, testBytesReplace)
}
if err = b.Delete(); err != nil {
t.Errorf("failed to delete Blob '%v:%v:%v': %v", e.w.Name, e.f.Name, b.Name, err)
}
2021-12-25 02:54:18 -05:00
}