Skip to content
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

feat: add cypress trigger type #3439

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/executor/trigger/traceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/kubeshop/tracetest/server/test/trigger"
)

const TRACEID_EXPRESSION = "${env:TRACE_ID}"

func TRACEID() Triggerer {
return &traceidTriggerer{}
}
Expand All @@ -30,6 +32,10 @@ func (t *traceidTriggerer) Type() trigger.TriggerType {
}

func (t *traceidTriggerer) Resolve(ctx context.Context, test test.Test, opts *ResolveOptions) (test.Test, error) {
if test.Trigger.Type == trigger.TriggerTypeCypress {
jorgeepc marked this conversation as resolved.
Show resolved Hide resolved
test.Trigger.TraceID = &trigger.TraceIDRequest{ID: TRACEID_EXPRESSION}
}

traceid := test.Trigger.TraceID
if traceid == nil {
return test, fmt.Errorf("no settings provided for TRACEID triggerer")
Expand Down
2 changes: 1 addition & 1 deletion server/executor/trigger_resolver_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (r triggerResolverWorker) ProcessItem(ctx context.Context, job Job) {
}

if trigger.IsTraceIDBasedTrigger(job.Test.Trigger.Type) {
traceIDFromParam, err := trace.TraceIDFromHex(job.Test.Trigger.TraceID.ID)
traceIDFromParam, err := trace.TraceIDFromHex(resolvedTest.Trigger.TraceID.ID)
if err == nil {
run.TraceID = traceIDFromParam
}
Expand Down
4 changes: 2 additions & 2 deletions server/test/trigger/trigger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ type triggerJSONV3 struct {

func (v3 triggerJSONV3) valid() bool {
// has a valid type and at least one not nil trigger type settings
return v3.Type != "" &&
return (v3.Type != "" &&
(v3.HTTP != nil ||
v3.GRPC != nil ||
v3.TraceID != nil ||
v3.Kafka != nil)
v3.Kafka != nil)) || v3.Type == TriggerTypeCypress
}

type triggerJSONV2 struct {
Expand Down
12 changes: 7 additions & 5 deletions web/src/models/Trigger.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,34 @@ type Trigger = {
request: TTriggerRequest;
};

type TRequest = object | null;

const EntryData = {
[TriggerTypes.http](request: object) {
[TriggerTypes.http](request: TRequest) {
return {
entryPoint: get(request, 'url', ''),
method: get(request, 'method', ''),
};
},
[TriggerTypes.grpc](request: object) {
[TriggerTypes.grpc](request: TRequest) {
return {
entryPoint: get(request, 'address', ''),
method: get(request, 'method', ''),
};
},
[TriggerTypes.traceid](request: object) {
[TriggerTypes.traceid](request: TRequest) {
return {
entryPoint: get(request, 'id', ''),
method: 'TraceID',
};
},
[TriggerTypes.cypress](request: object) {
[TriggerTypes.cypress](request: TRequest) {
return {
entryPoint: get(request, 'id', ''),
method: 'Cypress',
};
},
[TriggerTypes.kafka](request: object) {
[TriggerTypes.kafka](request: TRequest) {
let entryPoint = '';

const kafkaRequest = request as KafkaRequest;
Expand Down
7 changes: 4 additions & 3 deletions web/src/services/Test.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TestDefinitionService from './TestDefinition.service';
import GrpcService from './Triggers/Grpc.service';
import HttpService from './Triggers/Http.service';
import TraceIDService from './Triggers/TraceID.service';
import CypressService from './Triggers/Cypress.service';
import KafkaService from './Triggers/Kafka.service';

const authValidation = ({auth}: TDraftTest): boolean => {
Expand All @@ -34,14 +35,14 @@ const TriggerServiceMap = {
[SupportedPlugins.REST]: HttpService,
[SupportedPlugins.Kafka]: KafkaService,
[SupportedPlugins.TraceID]: TraceIDService,
[SupportedPlugins.Cypress]: TraceIDService,
[SupportedPlugins.Cypress]: CypressService,
} as const;

const TriggerServiceByTypeMap = {
[TriggerTypes.grpc]: GrpcService,
[TriggerTypes.http]: HttpService,
[TriggerTypes.traceid]: TraceIDService,
[TriggerTypes.cypress]: TraceIDService,
[TriggerTypes.cypress]: CypressService,
[TriggerTypes.kafka]: KafkaService,
} as const;

Expand All @@ -58,7 +59,7 @@ const TestService = () => ({
const trigger = {
type,
triggerType: type,
[requestType ?? type]: request,
...(request && {[requestType ?? type]: request}),
};

return {
Expand Down
21 changes: 21 additions & 0 deletions web/src/services/Triggers/Cypress.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {ITraceIDValues, ITriggerService} from 'types/Test.types';
import Validator from 'utils/Validator';

const CypressTriggerService = (): ITriggerService => ({
async getRequest() {
return null;
},

async validateDraft(draft) {
const {id} = draft as ITraceIDValues;
return Validator.required(id);
},

getInitialValues(request) {
const {id} = request as ITraceIDValues;

return {id};
},
});

export default CypressTriggerService();
2 changes: 1 addition & 1 deletion web/src/types/Test.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export type TTestRequestDetailsValues = IRpcValues | IHttpValues | IPostmanValue
export type TDraftTest<T = TTestRequestDetailsValues> = Partial<IBasicValues & T>;
export type TDraftTestForm<T = TTestRequestDetailsValues> = FormInstance<TDraftTest<T>>;

export type TTriggerRequest = HttpRequest | GRPCRequest | TraceIDRequest | KafkaRequest;
export type TTriggerRequest = HttpRequest | GRPCRequest | TraceIDRequest | KafkaRequest | null;
export interface ITriggerService {
getRequest(values: TDraftTest): Promise<TTriggerRequest>;
validateDraft(draft: TDraftTest): Promise<boolean>;
Expand Down
Loading