test: Unit test for parseStatuses()

This commit is contained in:
ditatompel 2024-06-03 22:18:24 +07:00
parent 58e2da0a67
commit 459271408d
No known key found for this signature in database
GPG key ID: 31D3D06D77950979

View file

@ -2,8 +2,56 @@ package monero
import (
"testing"
"github.com/jmoiron/sqlx/types"
)
func TestNode_parseStatuses(t *testing.T) {
tests := []struct {
name string
report Node
want string
}{
{
name: "Invalid initial LastCheckStatus type",
report: Node{
IsAvailable: true,
LastCheckStatus: types.JSONText("-invalid source-"),
},
want: "[2,2,2,2,1]",
},
{
name: "Node goes online",
report: Node{
IsAvailable: true,
LastCheckStatus: types.JSONText("[0,1,0,0,0]"),
},
want: "[1,0,0,0,1]",
},
{
name: "Node goes offline",
report: Node{
IsAvailable: false,
LastCheckStatus: types.JSONText("[0,1,0,1,1]"),
},
want: "[1,0,1,1,0]",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
n := &ProbeReport{
Node: Node{
IsAvailable: tt.report.IsAvailable,
LastCheckStatus: tt.report.LastCheckStatus,
},
}
if got := n.parseStatuses(); got != tt.want {
t.Errorf("Node.parseStatuses() = %v, want %v", got, tt.want)
}
})
}
}
func TestQueryLogs_toSQL(t *testing.T) {
tests := []struct {
name string
@ -13,7 +61,6 @@ func TestQueryLogs_toSQL(t *testing.T) {
wantSortBy string
wantSortDirection string
}{
// TODO: Add test cases.
{
name: "Default query",
fields: QueryLogs{