From 459271408d6da461a74659548ae2835e71b90081 Mon Sep 17 00:00:00 2001 From: ditatompel Date: Mon, 3 Jun 2024 22:18:24 +0700 Subject: [PATCH] test: Unit test for parseStatuses() --- internal/monero/report_test.go | 49 +++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/internal/monero/report_test.go b/internal/monero/report_test.go index aa4cd91..0b564b0 100644 --- a/internal/monero/report_test.go +++ b/internal/monero/report_test.go @@ -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{