package contract_test import ( "testing" "git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/fullsync/contract" "git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model" ) // TestSyncKindForDailyUsageOperation guards the mapping that makes a daily run // discoverable. Catalog.ListRuns drops any run whose operation maps to an empty // kind, so losing this case would make daily runs invisible in the monitor // without any error. func TestSyncKindForDailyUsageOperation(t *testing.T) { if got := contract.SyncKindForOperation(model.OperationPreviousDayUsageFullSync); got != contract.SyncKindTrafficUsageDaily { t.Fatalf("SyncKindForOperation(%q) = %q, want %q", model.OperationPreviousDayUsageFullSync, got, contract.SyncKindTrafficUsageDaily) } if !contract.SyncKindTrafficUsageDaily.Valid() { t.Fatal("SyncKindTrafficUsageDaily must be a valid kind") } if contract.SyncKindForOperation("some_unknown_operation") != "" { t.Fatal("an unknown operation must not be assigned a sync kind") } } // TestSyncKindForMonthlyHistoryOperation guards the mapping that makes a monthly // history run discoverable. Catalog.ListRuns drops any run whose operation maps // to an empty kind, so losing this case would make monthly history runs // invisible in the monitor without any error. func TestSyncKindForMonthlyHistoryOperation(t *testing.T) { if got := contract.SyncKindForOperation(model.OperationPreviousMonthUsageFullSync); got != contract.SyncKindTrafficUsageMonthly { t.Fatalf("SyncKindForOperation(%q) = %q, want %q", model.OperationPreviousMonthUsageFullSync, got, contract.SyncKindTrafficUsageMonthly) } } // TestDailyAndMonthlyUsageHaveDistinctSyncKinds keeps the usage runs separately // filterable. There are three distinct usage runs now: the MySQL current-month // snapshot, the TDengine daily history, and the TDengine monthly history. func TestDailyAndMonthlyUsageHaveDistinctSyncKinds(t *testing.T) { monthly := contract.SyncKindForOperation("current_month_usage_full_sync") daily := contract.SyncKindForOperation(model.OperationPreviousDayUsageFullSync) monthlyHistory := contract.SyncKindForOperation(model.OperationPreviousMonthUsageFullSync) if monthly == daily { t.Fatalf("current-month snapshot and daily history share the sync kind %q", daily) } if monthly == monthlyHistory { t.Fatalf("current-month snapshot and monthly history share the sync kind %q", monthlyHistory) } if daily == monthlyHistory { t.Fatalf("daily and monthly history share the sync kind %q", daily) } if !monthlyHistory.Valid() { t.Fatal("SyncKindTrafficUsageMonthly must be a valid kind") } }