Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maed223 committed Jun 18, 2024
1 parent e443528 commit 0196d30
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions admin_run_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,60 @@ func TestAdminRuns_ForceCancel(t *testing.T) {
})
}

func TestAdminRuns_ListFilterByDates(t *testing.T) {
skipUnlessEnterprise(t)

client := testClient(t)
ctx := context.Background()

org, orgCleanup := createOrganization(t, client)
defer orgCleanup()

wTest, wTestCleanup := createWorkspace(t, client, org)
defer wTestCleanup()

timestamp1 := time.Now().Format(time.RFC3339)
rTest1, rCleanup1 := createRun(t, client, wTest)
defer rCleanup1()

rTest2, rCleanup2 := createRun(t, client, wTest)
defer rCleanup2()
timestamp2 := time.Now().Format(time.RFC3339)

_, rCleanup3 := createRun(t, client, wTest)
defer rCleanup3()
timestamp3 := time.Now().Format(time.RFC3339)

t.Run("has valid date ranges", func(t *testing.T) {
rl, err := client.Admin.Runs.List(ctx, &AdminRunsListOptions{
CreatedAfter: timestamp1,
CreatedBefore: timestamp2,
})

require.NoError(t, err)
assert.Equal(t, 2, len(rl.Items))
assert.Equal(t, adminRunItemsContainsID(rl.Items, rTest1.ID), true)
assert.Equal(t, adminRunItemsContainsID(rl.Items, rTest2.ID), true)
})

t.Run("has no items when CreatedAfter and CreatedBefore datetimes has no overlap", func(t *testing.T) {
rl, err := client.Admin.Runs.List(ctx, &AdminRunsListOptions{
CreatedAfter: timestamp3,
CreatedBefore: timestamp2,
})

require.NoError(t, err)
assert.Equal(t, 0, len(rl.Items))
})

t.Run("errors with invalid input for CreatedAfter", func(t *testing.T) {
_, err := client.Admin.Runs.List(ctx, &AdminRunsListOptions{
CreatedAfter: "invalid",
})
assert.Error(t, err)
})
}

func TestAdminRuns_AdminRunsListOptions_valid(t *testing.T) {
skipUnlessEnterprise(t)

Expand Down

0 comments on commit 0196d30

Please sign in to comment.