Skip to content

Commit

Permalink
fix: fix run id and suite run id to use integer instead of string
Browse files Browse the repository at this point in the history
… in openapi spec (#3146)

* fix: set test run id as integer

* fix(cli): convert string references to run id to int

* fix(server): convert run id from string to int

* fix(web): partial fix

* chore(frontend): fixing run id type

* fix(openapi): fix test suite run id type

* fix(cli): adapt cli to use new run id types

* fix(server): use new run id type

* fix(cli): tests

* fixing types and tests

---------

Co-authored-by: Oscar Reyes <[email protected]>
  • Loading branch information
mathnogueira and xoscar authored Sep 11, 2023
1 parent e14b3eb commit 6403f4f
Show file tree
Hide file tree
Showing 65 changed files with 172 additions and 189 deletions.
2 changes: 1 addition & 1 deletion api/definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ components:
type: string
description: resource ID
runId:
type: string
type: integer
description: run ID
type:
type: string
Expand Down
2 changes: 1 addition & 1 deletion api/expressions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ components:
testId:
type: string
runId:
type: string
type: integer
spanId:
type: string
selector:
Expand Down
4 changes: 2 additions & 2 deletions api/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ components:
type: object
properties:
id:
type: string
type: integer
readOnly: true
traceId:
type: string
Expand Down Expand Up @@ -230,7 +230,7 @@ components:
testSuiteId:
type: string
testSuiteRunId:
type: string
type: integer

RunInformation:
type: object
Expand Down
2 changes: 1 addition & 1 deletion api/testsuites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ components:
type: object
properties:
id:
type: string
type: integer
readOnly: true
version:
type: integer
Expand Down
4 changes: 2 additions & 2 deletions cli/formatters/test_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ func (f testRun) getColoredText(passed bool, text string) string {
return pterm.FgRed.Sprintf(text)
}

func (f testRun) GetRunLink(testID, runID string) string {
return fmt.Sprintf("%s/test/%s/run/%s/test", f.baseURLFn(), testID, runID)
func (f testRun) GetRunLink(testID string, runID int32) string {
return fmt.Sprintf("%s/test/%s/run/%d/test", f.baseURLFn(), testID, runID)
}

func (f testRun) getDeepLink(baseLink string, index int, spanID string) string {
Expand Down
10 changes: 5 additions & 5 deletions cli/formatters/test_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestJSON(t *testing.T) {
Name: openapi.PtrString("Testcase 1"),
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
Id: openapi.PtrInt32(1),
State: openapi.PtrString("FINISHED"),
Result: &openapi.AssertionResults{
AllPassed: openapi.PtrBool(true),
Expand All @@ -43,7 +43,7 @@ func TestSuccessfulTestRunOutput(t *testing.T) {
Name: openapi.PtrString("Testcase 1"),
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
Id: openapi.PtrInt32(1),
State: openapi.PtrString("FINISHED"),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
Result: &openapi.AssertionResults{
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestSuccessfulTestRunOutputWithResult(t *testing.T) {
},
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
Id: openapi.PtrInt32(1),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
State: openapi.PtrString("FINISHED"),
Result: &openapi.AssertionResults{
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestFailingTestOutput(t *testing.T) {
},
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
Id: openapi.PtrInt32(1),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
Result: &openapi.AssertionResults{
AllPassed: openapi.PtrBool(false),
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestFailingTestOutputWithPadding(t *testing.T) {
},
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
Id: openapi.PtrInt32(1),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
Result: &openapi.AssertionResults{
AllPassed: openapi.PtrBool(false),
Expand Down
4 changes: 2 additions & 2 deletions cli/formatters/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ func (f testSuiteRun) getColoredText(passed bool, text string) string {
return pterm.FgRed.Sprintf(text)
}

func (f testSuiteRun) getRunLink(tsID, runID string) string {
return fmt.Sprintf("%s/testsuite/%s/run/%s", f.baseURLFn(), tsID, runID)
func (f testSuiteRun) getRunLink(tsID string, runID int32) string {
return fmt.Sprintf("%s/testsuite/%s/run/%d", f.baseURLFn(), tsID, runID)
}
12 changes: 6 additions & 6 deletions cli/openapi/model_resolve_context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions cli/openapi/model_test_run.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions cli/openapi/model_test_suite_run.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions cli/runner/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runner
import (
"context"
"fmt"
"strconv"

"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/openapi"
Expand Down Expand Up @@ -97,13 +96,9 @@ func (r testRunner) StartRun(ctx context.Context, resource any, runInfo openapi.
func (r testRunner) UpdateResult(ctx context.Context, result RunResult) (RunResult, error) {
test := result.Resource.(openapi.TestResource)
run := result.Run.(openapi.TestRun)
runID, err := strconv.Atoi(run.GetId())
if err != nil {
return RunResult{}, fmt.Errorf("invalid test run id format: %w", err)
}

updated, _, err := r.openapiClient.ApiApi.
GetTestRun(ctx, test.Spec.GetId(), int32(runID)).
GetTestRun(ctx, test.Spec.GetId(), run.GetId()).
Execute()

if err != nil {
Expand All @@ -123,16 +118,12 @@ func (r testRunner) UpdateResult(ctx context.Context, result RunResult) (RunResu
func (r testRunner) JUnitResult(ctx context.Context, result RunResult) (string, error) {
test := result.Resource.(openapi.TestResource)
run := result.Run.(openapi.TestRun)
runID, err := strconv.Atoi(run.GetId())
if err != nil {
return "", fmt.Errorf("invalid run id format: %w", err)
}

junit, _, err := r.openapiClient.ApiApi.
GetRunResultJUnit(
ctx,
test.Spec.GetId(),
int32(runID),
int32(run.GetId()),
).
Execute()
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions cli/runner/testsuite_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runner
import (
"context"
"fmt"
"strconv"

"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/openapi"
Expand Down Expand Up @@ -97,13 +96,9 @@ func (r testSuiteRunner) StartRun(ctx context.Context, resource any, runInfo ope
func (r testSuiteRunner) UpdateResult(ctx context.Context, result RunResult) (RunResult, error) {
testSuite := result.Resource.(openapi.TestSuiteResource)
run := result.Run.(openapi.TestSuiteRun)
runID, err := strconv.Atoi(run.GetId())
if err != nil {
return RunResult{}, fmt.Errorf("invalid test suite run id format: %w", err)
}

updated, _, err := r.openapiClient.ApiApi.
GetTestSuiteRun(ctx, testSuite.Spec.GetId(), int32(runID)).
GetTestSuiteRun(ctx, testSuite.Spec.GetId(), *run.Id).
Execute()

if err != nil {
Expand Down
11 changes: 2 additions & 9 deletions server/http/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"net/http"
"strconv"

"github.com/kubeshop/tracetest/server/assertions/selectors"
"github.com/kubeshop/tracetest/server/datastore"
Expand Down Expand Up @@ -448,14 +447,8 @@ func (c *controller) buildDataStores(ctx context.Context, info openapi.ResolveRe
}}, ds...)
}

if context.RunId != "" && context.TestId != "" {
runId, err := strconv.Atoi(context.RunId)

if err != nil {
return [][]expression.DataStore{}, err
}

run, err := c.testRunRepository.GetRun(ctx, id.ID(context.TestId), runId)
if context.TestId != "" && context.RunId > 0 {
run, err := c.testRunRepository.GetRun(ctx, id.ID(context.TestId), int(context.RunId))
if err != nil {
return [][]expression.DataStore{}, err
}
Expand Down
Loading

0 comments on commit 6403f4f

Please sign in to comment.