Skip to content

Commit

Permalink
feat: accept trigger error and run state from endpoint (#3335)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed Nov 3, 2023
1 parent d2ec14f commit 6bb9e63
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api/triggers.yaml
Expand Up @@ -33,3 +33,17 @@ components:
$ref: "./traceid.yaml#/components/schemas/TRACEIDResponse"
kafka:
$ref: "./kafka.yaml#/components/schemas/KafkaResponse"
error:
$ref: "#/components/schemas/TriggerError"

TriggerError:
type: object
properties:
connectionError:
type: boolean
runningOnContainer:
type: boolean
targetsLocalhost:
type: boolean
message:
type: string
232 changes: 232 additions & 0 deletions cli/openapi/model_trigger_error.go

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

36 changes: 36 additions & 0 deletions cli/openapi/model_trigger_result_trigger_result.go

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

1 change: 1 addition & 0 deletions server/http/controller.go
Expand Up @@ -735,6 +735,7 @@ func (c *controller) UpdateTestRun(ctx context.Context, testID string, runID int
// Prevents bad data in other fields to override correct data
existingRun.TriggerResult = run.TriggerResult
existingRun.Trace = traces.MergeTraces(existingRun.Trace, run.Trace)
existingRun.State = run.State

err = c.testRunRepository.UpdateRun(ctx, existingRun)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions server/http/mappings/tests.go
Expand Up @@ -128,10 +128,24 @@ func (m OpenAPI) TriggerResult(in trigger.TriggerResult) openapi.TriggerResult {
Grpc: m.GRPCResponse(in.GRPC),
Traceid: m.TraceIDResponse(in.TraceID),
Kafka: m.KafkaResponse(in.Kafka),
Error: m.TriggerError(in.Error),
},
}
}

func (m OpenAPI) TriggerError(in *trigger.TriggerError) openapi.TriggerError {
if in == nil {
return openapi.TriggerError{}
}

return openapi.TriggerError{
ConnectionError: in.ConnectionError,
RunningOnContainer: in.RunningOnContainer,
TargetsLocalhost: in.TargetsLocalhost,
Message: in.ErrorMessage,
}
}

func (m OpenAPI) Tests(in []test.Test) []openapi.Test {
tests := make([]openapi.Test, len(in))
for i, t := range in {
Expand Down Expand Up @@ -451,6 +465,20 @@ func (m Model) TriggerResult(in openapi.TriggerResult) trigger.TriggerResult {
HTTP: m.HTTPResponse(in.TriggerResult.Http),
GRPC: m.GRPCResponse(in.TriggerResult.Grpc),
TraceID: m.TraceIDResponse(in.TriggerResult.Traceid),
Error: m.TriggerError(in.TriggerResult.Error),
}
}

func (m Model) TriggerError(in openapi.TriggerError) *trigger.TriggerError {
if in.Message == "" {
return nil
}

return &trigger.TriggerError{
ConnectionError: in.ConnectionError,
RunningOnContainer: in.RunningOnContainer,
TargetsLocalhost: in.TargetsLocalhost,
ErrorMessage: in.Message,
}
}

Expand Down
37 changes: 37 additions & 0 deletions server/openapi/model_trigger_error.go
@@ -0,0 +1,37 @@
/*
* TraceTest
*
* OpenAPI definition for TraceTest endpoint and resources
*
* API version: 0.2.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package openapi

type TriggerError struct {
ConnectionError bool `json:"connectionError,omitempty"`

RunningOnContainer bool `json:"runningOnContainer,omitempty"`

TargetsLocalhost bool `json:"targetsLocalhost,omitempty"`

Message string `json:"message,omitempty"`
}

// AssertTriggerErrorRequired checks if the required fields are not zero-ed
func AssertTriggerErrorRequired(obj TriggerError) error {
return nil
}

// AssertRecurseTriggerErrorRequired recursively checks if required fields are not zero-ed in a nested slice.
// Accepts only nested slice of TriggerError (e.g. [][]TriggerError), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseTriggerErrorRequired(objSlice interface{}) error {
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
aTriggerError, ok := obj.(TriggerError)
if !ok {
return ErrTypeAssertionError
}
return AssertTriggerErrorRequired(aTriggerError)
})
}

0 comments on commit 6bb9e63

Please sign in to comment.