experimental-cli/project/peers_test.go

59 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"testing"
)
// TEST CASE: Attempting to getPeerStatus() of peer that
// does not exist.
func TestGetPeerStatus(t *testing.T) {
resetDB()
mHash := "USER.RJFSFK8YZ8XGTGKQDMSQCQPQXKH8GPRCDY86YZCFQ1QRKYEF48MG"
status := getPeerStatus(mHash)
if status != "unknown" {
t.Fatalf("Expected `unknown`, got %s", status)
}
2020-12-10 13:16:20 +00:00
setPeerStatus(mHash, following)
status2 := getPeerStatus(mHash)
if status2 != "following" {
t.Fatalf("Expected `following`, got %s", status)
}
2020-12-10 13:16:20 +00:00
peer := listPeers()[0]
if peer.mhash != mHash {
t.Fail()
}
if peer.status != following {
t.Fail()
}
}
2020-09-24 23:43:11 +00:00
2020-12-10 13:16:20 +00:00
func TestSetPeerStatus(t *testing.T) {
2020-09-24 23:43:11 +00:00
defer func() {
r := recover()
2020-09-27 13:46:44 +00:00
if r == nil {
err := "Should not be able to block and follow at the same time %s"
t.Errorf(err, r)
2020-09-24 23:43:11 +00:00
}
}()
resetDB()
mHash := "USER.GM84FEYKRQ1QFCZY68YDCRPG8HKXQPQCQSMDQKGTGX8ZY8KFSFJR"
2020-12-10 13:16:20 +00:00
setPeerStatus(mHash, following)
setPeerStatus(mHash, blocked)
2020-09-24 23:43:11 +00:00
}
2020-12-11 13:24:18 +00:00
func TestRemovePeer(t *testing.T) {
resetDB()
mHash := "USER.GM84FEYKRQ1QFCZY68YDCRPG8HKXQPQCQSMDQKGTGX8ZY8KFSFJR"
setPeerStatus(mHash, following)
removePeer(mHash)
if getPeerStatus(mHash) != unknown {
t.Fail()
}
}