Debug GetRequestJobs function and add unit tests
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@ -3,6 +3,7 @@ package client
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"forge.redroom.link/yves/meowlib"
|
||||
@ -79,3 +80,52 @@ func TestHidePeer(t *testing.T) {
|
||||
os.Remove("test.id")
|
||||
}
|
||||
}
|
||||
|
||||
// test GetRequestJobs
|
||||
func TestGetRequestJobs(t *testing.T) {
|
||||
// Create a mock Identity object
|
||||
id := &Identity{
|
||||
Peers: []Peer{
|
||||
{
|
||||
MyPullServers: []string{"server1", "server2"},
|
||||
MyLookupKp: meowlib.NewKeyPair(),
|
||||
},
|
||||
{
|
||||
MyPullServers: []string{"server3", "server4"},
|
||||
MyLookupKp: meowlib.NewKeyPair(),
|
||||
},
|
||||
},
|
||||
unlockedHiddenPeers: []Peer{
|
||||
{
|
||||
MyPullServers: []string{"server5", "server6"},
|
||||
MyLookupKp: meowlib.NewKeyPair(),
|
||||
},
|
||||
},
|
||||
}
|
||||
id.MessageServers = ServerStorage{
|
||||
DbFile: "test.db",
|
||||
}
|
||||
GetConfig().SetMemPass("test")
|
||||
GetConfig().SetIdentity(id)
|
||||
for i := 1; i < 10; i++ {
|
||||
// initialize a Server with name "server+i"
|
||||
srv := CreateServerFromUrl("server" + strconv.Itoa(i))
|
||||
id.MessageServers.StoreServer(srv)
|
||||
}
|
||||
// Call GetRequestJobs
|
||||
jobs := id.GetRequestJobs()
|
||||
|
||||
// Check that the returned list is as expected
|
||||
assert.Equal(t, 6, len(jobs), "Expected 6 jobs")
|
||||
|
||||
// Check that each job has the correct server and lookup keys
|
||||
for _, job := range jobs {
|
||||
//fmt.Println(job.Server.GetUid(), job.LookupKeys)
|
||||
assert.Contains(t, []string{"server1", "server2", "server3", "server4", "server5", "server6"}, job.Server.GetUid(), "Unexpected server UID")
|
||||
assert.Len(t, job.LookupKeys, 1, "Expected 1 lookup key per job")
|
||||
}
|
||||
|
||||
// Clean up
|
||||
// recursively remove the test.db folder
|
||||
os.RemoveAll("test.db")
|
||||
}
|
||||
|
Reference in New Issue
Block a user