[client.keyset] added test for 'Store()'/'Fetch()' mecanism
This commit is contained in:
parent
703db73f30
commit
2560da5bbc
|
@ -1,6 +1,7 @@
|
|||
package keyset
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"git.xdrm.io/schastsp/lib/context"
|
||||
"git.xdrm.io/schastsp/lib/scha"
|
||||
"testing"
|
||||
|
@ -117,4 +118,51 @@ func TestDecrementMinimum(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func TestRestore(t *testing.T){
|
||||
|
||||
var buffer, srcData bytes.Buffer;
|
||||
var src, dst *Set;
|
||||
var ctx *context.Context;
|
||||
var err error;
|
||||
|
||||
/* (1) Create a context */
|
||||
ctx, err = context.Create(2.2);
|
||||
if err != nil { t.Fatalf("[Unexpected error] %s", err); }
|
||||
|
||||
/* (2) Create our source */
|
||||
src, err = Create(ctx);
|
||||
if err != nil { t.Fatalf("[Unexpected error] %s", err); }
|
||||
|
||||
/* (3) Store it to buffer (+to another buffer to check after) */
|
||||
buffer.Reset(); srcData.Reset()
|
||||
err = src.Store(&buffer);
|
||||
if err != nil { t.Fatalf("[Unexpected error] %s", err); }
|
||||
err = src.Store(&srcData);
|
||||
if err != nil { t.Fatalf("[Unexpected error] %s", err); }
|
||||
|
||||
/* (4) Create our target */
|
||||
dst, err = Create(ctx);
|
||||
if err != nil { t.Fatalf("[Unexpected error] %s", err); }
|
||||
|
||||
/* (5) Restore from buffer */
|
||||
err = dst.Fetch(&buffer);
|
||||
if err != nil { t.Fatalf("[Unexpected error] %s", err); }
|
||||
|
||||
/* (6) Get both data */
|
||||
dst.Store(&buffer) // dst data is in buffer
|
||||
if err != nil { t.Fatalf("[Unexpected error] %s", err); }
|
||||
|
||||
if len(buffer.Bytes()) != len(srcData.Bytes()) || buffer.String() != srcData.String() {
|
||||
t.Fatalf("Expected restored keyset to be equal to original ; expected %x ; got %x", srcData, buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue