2022-04-08 05:59:40 +02:00
|
|
|
package data
|
2022-01-09 06:59:28 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2022-04-03 07:27:20 +02:00
|
|
|
func TestEncryptDecrypt(t *testing.T) {
|
2022-04-08 05:59:40 +02:00
|
|
|
k1 := EncryptionKey("key")
|
|
|
|
k2 := EncryptionKey("key")
|
2022-04-03 07:27:20 +02:00
|
|
|
if string(k1) != string(k2) {
|
|
|
|
t.Fatalf("Expected EncryptionKey to be deterministic!")
|
|
|
|
}
|
|
|
|
|
|
|
|
ciphertext, nonce, err := Encrypt("key", []byte("hello world!"), []byte("extra"))
|
2022-10-28 06:53:47 +02:00
|
|
|
checkError(t, err)
|
2022-04-03 07:27:20 +02:00
|
|
|
plaintext, err := Decrypt("key", ciphertext, []byte("extra"), nonce)
|
2022-10-28 06:53:47 +02:00
|
|
|
checkError(t, err)
|
2022-04-03 07:27:20 +02:00
|
|
|
if string(plaintext) != "hello world!" {
|
|
|
|
t.Fatalf("Expected decrypt(encrypt(x)) to work, but it didn't!")
|
|
|
|
}
|
|
|
|
}
|
2022-04-09 03:23:17 +02:00
|
|
|
|
2022-10-28 06:53:47 +02:00
|
|
|
func checkError(t *testing.T, err error) {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-24 06:42:22 +02:00
|
|
|
func TestCustomColumnSerialization(t *testing.T) {
|
2022-10-28 06:53:47 +02:00
|
|
|
cc1 := CustomColumn{
|
|
|
|
Name: "name1",
|
|
|
|
Val: "val1",
|
|
|
|
}
|
|
|
|
cc2 := CustomColumn{
|
|
|
|
Name: "name2",
|
|
|
|
Val: "val2",
|
|
|
|
}
|
2022-10-24 06:42:22 +02:00
|
|
|
var ccs CustomColumns = make(CustomColumns, 0)
|
2022-10-28 06:53:47 +02:00
|
|
|
|
|
|
|
// Empty array
|
2022-10-24 06:42:22 +02:00
|
|
|
v, err := ccs.Value()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected err: %v", err)
|
|
|
|
}
|
|
|
|
val := string(v.([]uint8))
|
|
|
|
if val != "[]" {
|
|
|
|
t.Fatalf("unexpected val for empty CustomColumns: %#v", val)
|
|
|
|
}
|
2022-10-28 06:53:47 +02:00
|
|
|
|
|
|
|
// Non-empty array
|
|
|
|
ccs = append(ccs, cc1, cc2)
|
|
|
|
v, err = ccs.Value()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected err: %v", err)
|
|
|
|
}
|
|
|
|
val = string(v.([]uint8))
|
|
|
|
if val != "[{\"name\":\"name1\",\"value\":\"val1\"},{\"name\":\"name2\",\"value\":\"val2\"}]" {
|
|
|
|
t.Fatalf("unexpected val for empty CustomColumns: %#v", val)
|
|
|
|
}
|
|
|
|
|
2022-10-24 06:42:22 +02:00
|
|
|
}
|