forked from oleiade/trousseau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trousseau_test.go
37 lines (30 loc) · 965 Bytes
/
trousseau_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package trousseau
import (
"encoding/json"
"testing"
"github.com/oleiade/tempura"
"os"
)
func TestOpenTrousseau(t *testing.T) {
testData := make(map[string]interface{})
testData["crypto_type"] = ASYMMETRIC_ENCRYPTION
testData["crypto_algorithm"] = GPG_ENCRYPTION
testData["_data"] = []byte("abc")
jsonData, _ := json.Marshal(&testData)
tmp, _ := tempura.FromBytes("/tmp", "trousseau", jsonData)
defer tmp.File.Close()
defer os.Remove(tmp.File.Name())
tr, err := OpenTrousseau(tmp.File.Name())
if err != nil {
t.Fatal(err)
}
assert(t, tr.CryptoType == ASYMMETRIC_ENCRYPTION, "Wrong encryption type")
assert(t, tr.CryptoAlgorithm == GPG_ENCRYPTION, "Wrong encryption algorithm")
equals(t, tr.Data, []byte("abc"))
}
func TestOpenTrousseau_returns_err_when_file_does_not_exist(t *testing.T) {
_, err := OpenTrousseau("/does/not/exist")
if err == nil {
t.Fatalf("OpenTrousseau function didn't failed while loading non existing file")
}
}