MCPcopy Index your code
hub / github.com/coder/coder / TestAIBridgeListInterceptions

Function TestAIBridgeListInterceptions

enterprise/cli/aibridge_test.go:23–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestAIBridgeListInterceptions(t *testing.T) {
24 t.Parallel()
25
26 t.Run("OK", func(t *testing.T) {
27 t.Parallel()
28
29 dv := coderdtest.DeploymentValues(t)
30 dv.AI.BridgeConfig.Enabled = true
31 ownerClient, db, owner := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
32 Options: &coderdtest.Options{
33 DeploymentValues: dv,
34 },
35 LicenseOptions: &coderdenttest.LicenseOptions{
36 Features: license.Features{
37 codersdk.FeatureAIBridge: 1,
38 },
39 },
40 })
41 _, member := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID)
42 now := dbtime.Now()
43 interception1 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
44 InitiatorID: member.ID,
45 StartedAt: now.Add(-time.Hour),
46 }, &now)
47 interception2EndedAt := now.Add(time.Minute)
48 interception2 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
49 InitiatorID: member.ID,
50 StartedAt: now,
51 }, &interception2EndedAt)
52 interception3EndedAt := now.Add(-time.Hour)
53 interception3 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
54 InitiatorID: owner.UserID,
55 StartedAt: now.Add(-2 * time.Hour),
56 }, &interception3EndedAt)
57
58 args := []string{
59 "aibridge",
60 "interceptions",
61 "list",
62 }
63 inv, root := newCLI(t, args...)
64 //nolint:gocritic // Owner can read all interceptions.
65 clitest.SetupConfig(t, ownerClient, root)
66
67 ctx := testutil.Context(t, testutil.WaitLong)
68
69 out := bytes.NewBuffer(nil)
70 inv.Stdout = out
71 err := inv.WithContext(ctx).Run()
72 require.NoError(t, err)
73
74 // Owner sees all interceptions. Ordered by started_at DESC.
75 requireHasInterceptions(t, out.Bytes(), []uuid.UUID{interception2.ID, interception1.ID, interception3.ID})
76 })
77
78 t.Run("Filter", func(t *testing.T) {
79 t.Parallel()
80

Callers

nothing calls this directly

Calls 15

DeploymentValuesFunction · 0.92
NewWithDatabaseFunction · 0.92
CreateAnotherUserFunction · 0.92
NowFunction · 0.92
AIBridgeInterceptionFunction · 0.92
SetupConfigFunction · 0.92
ContextFunction · 0.92
newCLIFunction · 0.85
requireHasInterceptionsFunction · 0.85
WithContextMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected