test(quality): cover routing sqlite overlay hotspots
This commit is contained in:
@@ -561,3 +561,86 @@ func TestSyncProviderAccountsFromImportBatchPromotesSingleReadyGatewayAccount(t
|
||||
t.Fatalf("LastProbeStatus = %q, want gateway_ready", account.LastProbeStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncProviderAccountsFromLatestImportBatchesSyncsEachLatestReconcilableBatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
store := openTestDBWithFK(t)
|
||||
ctx := context.Background()
|
||||
hostID := createTestHost(t, store)
|
||||
packID := createTestPack(t, store)
|
||||
providerAID, err := store.Providers().Create(ctx, Provider{
|
||||
PackID: packID,
|
||||
ProviderID: "provider-a",
|
||||
DisplayName: "Provider A",
|
||||
BaseURL: "https://api.provider-a.example/v1",
|
||||
Platform: "openai",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Providers().Create(provider-a) error = %v", err)
|
||||
}
|
||||
providerBID, err := store.Providers().Create(ctx, Provider{
|
||||
PackID: packID,
|
||||
ProviderID: "provider-b",
|
||||
DisplayName: "Provider B",
|
||||
BaseURL: "https://api.provider-b.example/v1",
|
||||
Platform: "openai",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Providers().Create(provider-b) error = %v", err)
|
||||
}
|
||||
|
||||
createBatchWithAccount := func(providerID int64, accountID, keyFingerprint string) {
|
||||
t.Helper()
|
||||
batchID, err := store.ImportBatches().Create(ctx, ImportBatch{
|
||||
HostID: hostID,
|
||||
PackID: packID,
|
||||
ProviderID: providerID,
|
||||
Mode: "strict",
|
||||
BatchStatus: "succeeded",
|
||||
AccessStatus: "subscription_ready",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("ImportBatches().Create(%s) error = %v", accountID, err)
|
||||
}
|
||||
if _, err := store.ImportBatchItems().Create(ctx, ImportBatchItem{
|
||||
BatchID: batchID,
|
||||
KeyFingerprint: keyFingerprint,
|
||||
AccountStatus: "passed",
|
||||
ProbeSummaryJSON: `{"account_id":"` + accountID + `","probe_status":"passed"}`,
|
||||
}); err != nil {
|
||||
t.Fatalf("ImportBatchItems().Create(%s) error = %v", accountID, err)
|
||||
}
|
||||
for _, resource := range []ManagedResource{
|
||||
{BatchID: batchID, HostID: hostID, ResourceType: "group", HostResourceID: "group-" + accountID, ResourceName: "Group " + accountID},
|
||||
{BatchID: batchID, HostID: hostID, ResourceType: "account", HostResourceID: accountID, ResourceName: "Account " + accountID},
|
||||
} {
|
||||
if _, err := store.ManagedResources().Create(ctx, resource); err != nil {
|
||||
t.Fatalf("ManagedResources().Create(%s/%s) error = %v", accountID, resource.ResourceType, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createBatchWithAccount(providerAID, "account-a1", "sha256:a1")
|
||||
createBatchWithAccount(providerBID, "account-b1", "sha256:b1")
|
||||
|
||||
if err := SyncProviderAccountsFromLatestImportBatches(ctx, store); err != nil {
|
||||
t.Fatalf("SyncProviderAccountsFromLatestImportBatches() error = %v", err)
|
||||
}
|
||||
|
||||
accountA, err := store.ProviderAccounts().GetByHostIDAndAccountID(ctx, hostID, "account-a1")
|
||||
if err != nil {
|
||||
t.Fatalf("ProviderAccounts().GetByHostIDAndAccountID(account-a1) error = %v", err)
|
||||
}
|
||||
if accountA.AccountStatus != ProviderAccountStatusActive || accountA.KeyFingerprint != "sha256:a1" {
|
||||
t.Fatalf("account-a1 = %+v, want active sha256:a1", accountA)
|
||||
}
|
||||
|
||||
accountB, err := store.ProviderAccounts().GetByHostIDAndAccountID(ctx, hostID, "account-b1")
|
||||
if err != nil {
|
||||
t.Fatalf("ProviderAccounts().GetByHostIDAndAccountID(account-b1) error = %v", err)
|
||||
}
|
||||
if accountB.AccountStatus != ProviderAccountStatusActive || accountB.KeyFingerprint != "sha256:b1" {
|
||||
t.Fatalf("account-b1 = %+v, want active sha256:b1", accountB)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user