Add resetDB() helper
This commit is contained in:
parent
26309d7dae
commit
da85cfb2b5
|
@ -85,13 +85,19 @@ func GetConfig(key string) []byte {
|
|||
if err != nil {
|
||||
log.Fatalf("Unable to retrieve config key(1): %s", err)
|
||||
}
|
||||
|
||||
var result string
|
||||
for rows.Next() {
|
||||
|
||||
if rows.Next() {
|
||||
err := rows.Scan(&result)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to retrieve config key(2): %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(result) < 1 {
|
||||
log.Fatalf("Attempted to retrieve non-existent key: %s", key)
|
||||
}
|
||||
|
||||
return []byte(result)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,41 @@
|
|||
package pigeon
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetUpTeardown(t *testing.T) {
|
||||
db := openDB()
|
||||
err := db.Ping()
|
||||
func resetDB() {
|
||||
tx, err := Database.Begin()
|
||||
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
log.Fatalf("Failed to start transaction: %s", err)
|
||||
}
|
||||
|
||||
for i := len(migrations) - 1; i >= 0; i-- {
|
||||
_, err := tx.Exec(migrations[i].down)
|
||||
if err != nil {
|
||||
log.Fatalf("Migration failure: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, migration := range migrations {
|
||||
_, err := tx.Exec(migration.up)
|
||||
if err != nil {
|
||||
log.Fatalf("Migration failure: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if tx.Commit() != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetUpTeardown(t *testing.T) {
|
||||
resetDB()
|
||||
db := Database
|
||||
err := db.Ping()
|
||||
if err != nil {
|
||||
t.Fatalf("Test setup failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package pigeon
|
|||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
|
@ -19,22 +18,16 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
|
|||
return pub, priv
|
||||
}
|
||||
|
||||
// GetIdentity retrieves the user's signing key
|
||||
func GetIdentity() []byte {
|
||||
fmt.Println("Add database query here")
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
// EncodeUserMhash Takes a []byte and converts it to a B32
|
||||
// string in the format "USER.DATA.ED25519"
|
||||
func EncodeUserMhash(pubKey []byte) string {
|
||||
b32 := B32Encode(pubKey)
|
||||
b32Length := len(b32)
|
||||
// func EncodeUserMhash(pubKey []byte) string {
|
||||
// b32 := B32Encode(pubKey)
|
||||
// b32Length := len(b32)
|
||||
|
||||
if b32Length != 52 {
|
||||
m := "Expected %s to be 52 bytes long. Got %d"
|
||||
log.Fatal(m, b32, b32Length)
|
||||
}
|
||||
// if b32Length != 52 {
|
||||
// m := "Expected %s to be 52 bytes long. Got %d"
|
||||
// log.Fatal(m, b32, b32Length)
|
||||
// }
|
||||
|
||||
return fmt.Sprintf("%s%s", UserSigil, b32)
|
||||
}
|
||||
// return fmt.Sprintf("%s%s", UserSigil, b32)
|
||||
// }
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCreateIdentity(t *testing.T) {
|
||||
resetDB()
|
||||
pub, priv := CreateIdentity()
|
||||
dbPubKey := GetConfig("public_key")
|
||||
dbPrivKey := GetConfig("private_key")
|
||||
|
|
Loading…
Reference in New Issue