diff --git a/test/integration/api/allocation/allocation_smoke_test.go b/test/integration/api/allocation/allocation_smoke_test.go new file mode 100644 index 0000000..192f5e3 --- /dev/null +++ b/test/integration/api/allocation/allocation_smoke_test.go @@ -0,0 +1,50 @@ +package allocation + +import ( + "testing" + + "github.com/opencost/opencost-integration-tests/pkg/api" + "github.com/opencost/opencost-integration-tests/pkg/env" +) + +func TestAllocationSmoke(t *testing.T) { + + apiClient := api.NewAPI() + + // logging incase we can trace potential env issues with go test -v + t.Logf("Smoke target (OPENCOST_URL or default): %s", env.GetDefaultURL()) + + testCases := []struct { + name string + window string + }{ + { + name: "SimpleValidQuery_1d", + window: "1d", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + + response, err := apiClient.GetAllocation(api.AllocationRequest{ + Window: tc.window, + }) + + if err != nil { + t.Fatalf("Error while calling Allocation API %v", err) + } + + if response.Code != 200 { + t.Errorf("/allocation returned non-200 code: %d", response.Code) + } + + itemCount := 0 + for _, step := range response.Data { + itemCount += len(step) + } + t.Logf("/allocation OK: code=%d, steps=%d, allocation items=%d", + response.Code, len(response.Data), itemCount) + }) + } +} diff --git a/test/integration/api/allocation/allocation_summary_smoke_test.go b/test/integration/api/allocation/allocation_summary_smoke_test.go new file mode 100644 index 0000000..19d2ee6 --- /dev/null +++ b/test/integration/api/allocation/allocation_summary_smoke_test.go @@ -0,0 +1,47 @@ +package allocation + +import ( + "testing" + + "github.com/opencost/opencost-integration-tests/pkg/api" + "github.com/opencost/opencost-integration-tests/pkg/env" +) + +func TestAllocationSummarySmoke(t *testing.T) { + + apiClient := api.NewAPI() + + // logging incase we can trace potential env issues with go test -v + t.Logf("Smoke target (OPENCOST_URL or default): %s", env.GetDefaultURL()) + + testCases := []struct { + name string + window string + }{ + { + name: "SimpleValidQuery_1d", + window: "1d", + }, + } + + for _, tc := range testCases { + + t.Run(tc.name, func(t *testing.T) { + + ar := api.AllocationRequest{ + Window: tc.window, + } + response, err := apiClient.GetAllocationSummary(ar) + if err != nil { + t.Fatalf("/allocation/summary window=%s request failed: %v", ar.Window, err) + } + + if response.Code != 200 { + t.Errorf("/allocation/summary window=%s returned non-200 code: %d", ar.Window, response.Code) + } + + t.Logf("/allocation/summary: code=%d, allocation sets returned: %d", + response.Code, len(response.Data.Sets)) + }) + } +} diff --git a/test/integration/api/allocation/test.bats b/test/integration/api/allocation/test.bats index 2d41bd7..1aa8d70 100644 --- a/test/integration/api/allocation/test.bats +++ b/test/integration/api/allocation/test.bats @@ -1,11 +1,21 @@ setup() { DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" - cd $DIR + cd "$DIR" } teardown() { : # nothing to tear down } + +@test "allocation: smoke test allocation" { + #60sec cap bc SDK http.Get has no timeout, avoids go test's default 10 min + go test -timeout 60s allocation_smoke_test.go +} + +@test "allocation: smoke test allocation summary" { + go test -timeout 60s allocation_summary_smoke_test.go +} + @test "allocation: controller kind consistency" { go test allocation_controller_consistency_test.go } diff --git a/test/integration/api/asset/assets_smoke_test.go b/test/integration/api/asset/assets_smoke_test.go new file mode 100644 index 0000000..e7f8035 --- /dev/null +++ b/test/integration/api/asset/assets_smoke_test.go @@ -0,0 +1,50 @@ +package assets + +import ( + "testing" + + "github.com/opencost/opencost-integration-tests/pkg/api" + "github.com/opencost/opencost-integration-tests/pkg/env" +) + +func TestAssetsSmoke(t *testing.T) { + + apiClient := api.NewAPI() + + // logging incase we can trace potential env issues with go test -v + t.Logf("Assets Smoke target (OPENCOST_URL or default): %s", env.GetDefaultURL()) + + testCases := []struct { + name string + window string + }{ + { + name: "ValidQueryTest", + window: "1d", + }, + } + + for _, tc := range testCases { + + t.Run(tc.name, func(t *testing.T) { + + ar := api.AssetsRequest{ + Window: tc.window, + } + response, err := apiClient.GetAssets(ar) + if err != nil { + t.Fatalf("/assets?window=%s request failed: %v", ar.Window, err) + } + + if response.Code != 200 { + t.Errorf("/assets?window=%s returned non-200 code: %d", ar.Window, response.Code) + } + + if len(response.Data) == 0 { + t.Logf("warning: /assets returned 200 but zero assets") + } + + t.Logf("/assets: code=%d, assets returned: %d", response.Code, len(response.Data)) + }) + } +} diff --git a/test/integration/api/asset/test.bats b/test/integration/api/asset/test.bats index a642c16..8c18591 100644 --- a/test/integration/api/asset/test.bats +++ b/test/integration/api/asset/test.bats @@ -1,12 +1,17 @@ setup() { DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" - cd $DIR + cd "$DIR" } teardown() { : # nothing to tear down } +@test "asset: Smoke Test" { + #60sec cap bc SDK http.Get has no timeout, avoids go test's default 10 min + go test -timeout 60s assets_smoke_test.go +} + @test "asset: Node Labels" { go test node_labels_test.go }