Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ linters:
- gosec
- govet
- lll
- noctx
- revive
- staticcheck
- unparam
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ mockgen: install-mockgen
@mkdir -p mock
$(MOCKGEN) -destination=mock/Repository.go -package=mock github.com/e2engine/core/repository EntityRepository,ResourceRepository,TestRepository,TestExecutionRepository,TestSuiteExecutionRepository
$(MOCKGEN) -destination=mock/Runtime.go -package=mock github.com/e2engine/core/execute/runtime Service,ServiceProvider,Router,RouterProvider
$(MOCKGEN) -destination=mock/Execute.go -package=mock github.com/e2engine/core/execute ProtocolExecutor
go generate ./...

.PHONY: lint
lint: install-golangci-lint
Expand Down
6 changes: 3 additions & 3 deletions api/service_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,14 +714,14 @@ func validTestSpec() model.TestSpec {
return model.TestSpec{
Tags: []string{"smoke"},
Request: model.RequestSpec{
HTTP: &model.HTTPRequestSpec{
HTTP: &model.HTTPRequest{
Method: "GET",
URL: "http://localhost:8080/health",
},
},
Expect: model.ExpectSpec{
HTTP: &model.HTTPExpectSpec{
Status: 200,
HTTP: &model.HTTPResponsePattern{
StatusCode: 200,
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion execute/call/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type GRPCCall struct {
}

type GRPCRequest struct {
RPC string
Service string
Method string
Metadata map[string][]string
Message []byte
}
Expand Down
6 changes: 1 addition & 5 deletions execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ type Worker[J Job, R JobExecutionResult] interface {
}

type ProtocolExecutor interface {
Execute(
ctx context.Context,
job *TestJob,
result *TestExecutionResult,
) error
Execute(ctx context.Context, job *TestJob) error
}

type TestExecutionResult struct {
Expand Down
135 changes: 135 additions & 0 deletions execute/match/match.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package match

import (
"encoding/json"

"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/dynamicpb"

"github.com/e2engine/core/internal/util"
"github.com/e2engine/core/model/matcher"
)

func IsStringMatched(
actual []byte,
expected *matcher.String,
) bool {
if expected == nil {
panic("string matcher must not be nil")
}

switch expected.Operator {
case matcher.StringMatchOperatorExists:
return true

case matcher.StringMatchOperatorNonEmpty:
return len(actual) > 0

case matcher.StringMatchOperatorEquals:
return string(actual) == expected.Value

default:
// Validation guarantees a supported operator.
panic("invalid string matcher operator")
}
}

func IsStringSliceMatched(
actual []string,
exists bool,
expected []matcher.String,
) bool {
if len(expected) == 0 {
panic("string matchers must not be empty")
}

if !exists {
return false
}

switch expected[0].Operator {
case matcher.StringMatchOperatorExists:
return true

case matcher.StringMatchOperatorNonEmpty:
for _, value := range actual {
if value != "" {
return true
}
}
return false

case matcher.StringMatchOperatorEquals:
expectedValues := make([]string, len(expected))
for i := range expected {
expectedValues[i] = expected[i].Value
}

return util.IsStringSlicesEqual(actual, expectedValues)

default:
panic("invalid string matcher operator")
}
}

func IsJSONMatched(
actual []byte,
expected *matcher.String,
) (bool, error) {
if expected == nil {
panic("JSON matcher must not be nil")
}

switch expected.Operator {
case matcher.StringMatchOperatorExists:
return json.Valid(actual), nil

case matcher.StringMatchOperatorNonEmpty:
return len(actual) > 0 && json.Valid(actual), nil

case matcher.StringMatchOperatorEquals:
return util.IsJSONEqual(
[]byte(expected.Value),
actual,
)

default:
// Validation guarantees a supported operator.
panic("invalid string matcher operator")
}
}

func IsGRPCMessageMatched(
actual proto.Message,
expected *matcher.GRPCMessage,
) (bool, error) {
if expected == nil {
panic("gRPC message matcher must not be nil")
}
switch expected.Operator {
case matcher.GRPCMessageMatchOperatorNonEmpty:
nonempty := false
actual.ProtoReflect().Range(
func(_ protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
nonempty = true
return false
},
)
return nonempty, nil
case matcher.GRPCMessageMatchOperatorEquals:
expectedMessage := dynamicpb.NewMessage(
actual.ProtoReflect().Descriptor(),
)
if err := protojson.Unmarshal(
[]byte(expected.Value),
expectedMessage,
); err != nil {
return false, err
}
return proto.Equal(actual, expectedMessage), nil
default:
panic("invalid gRPC message matcher operator")
}
}
Loading
Loading