package repository import ( "context" "errors" "testing" "evobgp/internal/store" "github.com/google/uuid" ) func TestPostgresModuleSnapshotMethodsRespectCancellationIntegration(t *testing.T) { p, tenant := queueIntegration(t) module := uuid.NewString() if _, err := p.pool.Exec(context.Background(), `INSERT INTO module(id,tenant_id,type,name) VALUES($1,$2,'CDN_CIDRS','cancel-snapshot')`, module, tenant); err != nil { t.Fatal(err) } ctx, cancel := context.WithCancel(context.Background()) cancel() if _, _, err := p.GetModulePrefixSnapshot(ctx, tenant, module); !errors.Is(err, context.Canceled) { t.Fatalf("get: %v", err) } if err := p.SetModulePrefixSnapshot(ctx, tenant, module, "hash", []store.PrefixRow{{Prefix: "192.0.2.0/24"}}); !errors.Is(err, context.Canceled) { t.Fatalf("set: %v", err) } if err := p.DeleteModulePrefixSnapshot(ctx, tenant, module); !errors.Is(err, context.Canceled) { t.Fatalf("delete: %v", err) } if err := p.SetModuleInputHash(ctx, tenant, module, "hash"); !errors.Is(err, context.Canceled) { t.Fatalf("input hash: %v", err) } rev := uuid.NewString() err := p.CreateRenderRevision(ctx, rev, tenant, module, nil, "cancel-hash", map[string]string{"bird.conf": "router id 192.0.2.1;\n"}, []store.PrefixRow{{Prefix: "203.0.113.0/24", Source: "test"}}) if !errors.Is(err, context.Canceled) { t.Fatalf("revision: %v", err) } var n int if err := p.pool.QueryRow(context.Background(), `SELECT count(*)::int FROM config_revision WHERE id=$1::uuid`, rev).Scan(&n); err != nil { t.Fatal(err) } if n != 0 { t.Fatal("cancelled revision write committed") } }