-
Notifications
You must be signed in to change notification settings - Fork 22
Add smoke tests for allocation, allocation summary, and assets endpoints #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
e-300
wants to merge
4
commits into
opencost:main
Choose a base branch
from
e-300:add-smoke-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ef45083
Add smoke tests for allocation, allocation summary, and assets endpoints
e-300 8946b9e
Address Copilot review feedback on smoke tests
e-300 7d7efa8
Revert "Address Copilot review feedback on smoke tests"
e-300 65cd388
Merge branch 'main' into add-smoke-tests
Manas23601 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| }) | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
test/integration/api/allocation/allocation_summary_smoke_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.