diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index b9f3cf4..4c7e692 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -24,4 +24,6 @@ jobs: run: make build - name: E2E tests + env: + TODO_ID: 2 run: sh ./tests/e2e-tests.sh diff --git a/internal/request/run_test.go b/internal/request/run_test.go index 73e8083..70c7e61 100644 --- a/internal/request/run_test.go +++ b/internal/request/run_test.go @@ -89,6 +89,46 @@ func TestCompileDefaultArg(t *testing.T) { } } +func TestCompileWithEnv(t *testing.T) { + t.Setenv("SOME_ID", "7") + + var requestDefault = &config.RequestSchema{ + Args: []map[string]string{ + { + "id": "1", + }, + }, + Method: "GET", + Endpoint: "http://jsonplaceholder.typicode.com/todos/{env.SOME_ID}", + Headers: []map[string]string{ + { + "TestId": "{id}", + }, + }, + } + + var expectedRequestId1 = &config.RequestSchema{ + Args: []map[string]string{ + { + "id": "1", + }, + }, + Method: "GET", + Endpoint: "http://jsonplaceholder.typicode.com/todos/7", + Headers: []map[string]string{ + { + "TestId": "5", + }, + }, + } + + requestId1 := compile(requestDefault, map[string]string{"id": "5"}) + + if !cmp.Equal(requestId1, expectedRequestId1) { + t.Fatalf("requestId1 is not the same as expectedRequestId5") + } +} + func TestGetMethod(t *testing.T) { // get if m, _ := getMethod("get"); m != http.MethodGet { diff --git a/tests/e2e-tests.sh b/tests/e2e-tests.sh index f47eec5..0db2825 100644 --- a/tests/e2e-tests.sh +++ b/tests/e2e-tests.sh @@ -65,3 +65,14 @@ else echo "FAIL: get-todo-formatted does not match output" exit 1 fi + +# GET with env vars +output_7=$(./bin/sendex run tests/get-todo-env.yml --raw) +desired_output_7=$(cat tests/get-todo-2.output) + +if [ "$output_7" = "$desired_output_7" ]; then + echo "PASS: get-todo-env matches expected output" +else + echo "FAIL: get-todo-env does not match output" + exit 1 +fi diff --git a/tests/get-todo-2.output b/tests/get-todo-2.output new file mode 100644 index 0000000..82c1f23 --- /dev/null +++ b/tests/get-todo-2.output @@ -0,0 +1,8 @@ +200 OK +Content-Type: application/json; charset=utf-8 +{ + "userId": 1, + "id": 2, + "title": "quis ut nam facilis et officia qui", + "completed": false +} diff --git a/tests/get-todo-env.yml b/tests/get-todo-env.yml new file mode 100644 index 0000000..ff45ad2 --- /dev/null +++ b/tests/get-todo-env.yml @@ -0,0 +1,7 @@ +method: GET +endpoint: http://jsonplaceholder.typicode.com/todos/{env.TODO_ID} +headers: + - Content-Type: application/json + - Accept: application/json +allow-headers: + - Content-Type