2019-08-28 16:07:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSavesUnencryptedKeys(t *testing.T) {
|
2019-10-19 17:29:25 +00:00
|
|
|
keys := 2
|
|
|
|
numKeys = &keys
|
2019-09-18 17:15:26 +00:00
|
|
|
ctnr := generateUnencryptedKeys(0 /* start index */)
|
2019-08-28 16:07:31 +00:00
|
|
|
buf := new(bytes.Buffer)
|
2019-09-09 21:31:19 +00:00
|
|
|
if err := SaveUnencryptedKeysToFile(buf, ctnr); err != nil {
|
2019-08-28 16:07:31 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
enc := buf.Bytes()
|
2019-09-09 21:31:19 +00:00
|
|
|
dec := &UnencryptedKeysContainer{}
|
2019-08-28 16:07:31 +00:00
|
|
|
if err := json.Unmarshal(enc, dec); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctnr, dec) {
|
|
|
|
t.Errorf("Wanted %v, received %v", ctnr, dec)
|
|
|
|
}
|
|
|
|
}
|