experimental-cli/project/util_test.go

46 lines
783 B
Go
Raw Normal View History

2020-09-10 12:33:41 +00:00
package main
import (
"bytes"
2020-12-12 15:36:43 +00:00
"fmt"
2020-09-10 12:33:41 +00:00
"testing"
)
func TestCreateIdentity(t *testing.T) {
resetDB()
pub, priv := CreateIdentity()
2020-12-12 15:36:43 +00:00
dbPubKey := FetchConfig("public_key")
dbPrivKey := FetchConfig("private_key")
2020-09-10 12:33:41 +00:00
if !bytes.Equal(pub, dbPubKey) {
t.Fail()
}
if !bytes.Equal(priv, dbPrivKey) {
t.Fail()
}
}
2020-12-12 15:36:43 +00:00
func TestShowIdentity(t *testing.T) {
resetDB()
result1 := showPubKeyOrNone()
if result1 != "NONE" {
t.Fail()
}
result2 := createOrShowIdentity()
sigil := result2[0:5]
if sigil != "USER." {
t.Fail()
}
if len(result2) != 57 {
t.Fail()
}
result3 := createOrShowIdentity()
if result2 != result3 {
fmt.Printf("=== result2: %s\n", result2)
fmt.Printf("=== result3: %s\n", result3)
t.Fail() //Expect createOrShowIdentity() to be idempotent.
}
}