From 82420529fda1a882b8090f9a3eee93ada70203f2 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Mon, 16 Sep 2024 10:36:32 -0300 Subject: [PATCH 1/2] feat: add URIs to schema Signed-off-by: Felipe Zipitria --- types/types.go | 13 +++++++++++-- types/types_test.go | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/types/types.go b/types/types.go index 81f22c0..213c01d 100644 --- a/types/types.go +++ b/types/types.go @@ -203,9 +203,18 @@ type Input struct { // URI allows you to declare the URI the test should use as part of the request line. // examples: // - name: URI - // value: "\"/get?hello=world\"" + // value: '/get?hello=world" URI *string `yaml:"uri,omitempty" json:"uri,omitempty" koanf:"uri,omitempty"` + // description: | + // URIs is a list of URIs that the test should use as part of the request line. + // If URIs is set, URI will be ignored. URIs is useful for tests that need to send multiple requests. + // Caveat: you cannot change the method or headers between requests. + // examples: + // - name: URIs + // value: ['/get?hello=world', '/request/this?var=value'] + URIs []string `yaml:"uris,omitempty" json:"uris,omitempty" koanf:"uris,omitempty"` + // description: | // FollowRedirect will expect the previous stage of the same test to have received a // redirect response, it will fail the test otherwise. The redirect location will be used @@ -336,7 +345,7 @@ type Response struct { // description: | // LogMessage specifies a message to be printed in the log of the backend server that sends the response. - // This can be helpful when debugging, to match resopnses sent by the backend to test executions. + // This can be helpful when debugging, to match responses sent by the backend to test executions. // examples: // - name: LogMessage // value: "\"Response splitting test 1\"" diff --git a/types/types_test.go b/types/types_test.go index 9d28ee7..3f719fc 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -33,6 +33,7 @@ tests: Accept: "*/*" encoded_request: "TXkgRGF0YQo=" uri: "/test" + uris: ["/test", "/multiple", "/uris"] protocol: "http" autocomplete_headers: false stop_magic: true @@ -84,6 +85,8 @@ var ftwTest = &FTWTest{ Input: Input{ DestAddr: helpers.StrPtr("127.0.0.1"), Port: helpers.IntPtr(80), + URI: helpers.StrPtr("/test"), + URIs: []string{"/test", "/multiple", "/uris"}, Method: helpers.StrPtr("OPTIONS"), Headers: map[string]string{ "User-Agent": "FTW Schema Tests", @@ -124,6 +127,8 @@ func TestUnmarshalFTWTest(t *testing.T) { expectedStage := expectedTest.Stages[j] assertions.Equal(expectedStage.Input.DestAddr, stage.Input.DestAddr) assertions.Equal(expectedStage.Input.Port, stage.Input.Port) + assertions.Equal(expectedStage.Input.URI, stage.Input.URI) + assertions.Equal(expectedStage.Input.URIs, stage.Input.URIs) assertions.Equal(expectedStage.Input.Method, stage.Input.Method) assertions.Len(stage.Input.Headers, len(expectedStage.Input.Headers)) From e9741ecf2d423cc37dd1116680d2d59eb97f3558 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Mon, 16 Sep 2024 11:32:08 -0300 Subject: [PATCH 2/2] chore: add gha for running tests also Signed-off-by: Felipe Zipitria --- test.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test.yml diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..678dc15 --- /dev/null +++ b/test.yml @@ -0,0 +1,25 @@ +name: Test +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened] + push: + branches: [main] + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Set up Go + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 + with: + go-version: ^1.21 + cache: true + + - name: Run Go Tests + run: go test -coverprofile coverage.out ./...