-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from ikramanop/feature/cases-variables-throug…
…h-tests feature: add cases variables
- Loading branch information
Showing
13 changed files
with
277 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- name: Test /do endpoint | ||
method: POST | ||
path: /do | ||
|
||
variables: | ||
name: name | ||
|
||
request: '{"{{ $name }}": "{{ .name }}"}' | ||
|
||
response: | ||
200: '{"{{ $num }}":{{ .num }}}' | ||
|
||
cases: | ||
- variables: | ||
num: num | ||
requestArgs: | ||
name: a | ||
responseArgs: | ||
200: | ||
num: 1 | ||
- requestArgs: | ||
name: b | ||
responseArgs: | ||
200: | ||
num: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
|
||
"github.com/lamoda/gonkey/mocks" | ||
"github.com/lamoda/gonkey/runner" | ||
) | ||
|
||
func TestProxy(t *testing.T) { | ||
m := mocks.NewNop("backend") | ||
if err := m.Start(); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer m.Shutdown() | ||
|
||
os.Setenv("BACKEND_ADDR", m.Service("backend").ServerAddr()) | ||
initServer() | ||
srv := httptest.NewServer(nil) | ||
|
||
runner.RunWithTesting(t, &runner.RunWithTestingParams{ | ||
Server: srv, | ||
TestsDir: "cases", | ||
Mocks: m, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
type Request struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
type Response struct { | ||
Num int `json:"num"` | ||
} | ||
|
||
func main() { | ||
initServer() | ||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
} | ||
|
||
func initServer() { | ||
http.HandleFunc("/do", Do) | ||
} | ||
|
||
func Do(w http.ResponseWriter, r *http.Request) { | ||
var response Response | ||
|
||
if r.Method != "POST" { | ||
response.Num = 0 | ||
fmt.Fprint(w, buildResponse(response)) | ||
return | ||
} | ||
|
||
jsonRequest, _ := ioutil.ReadAll(r.Body) | ||
request := buildRequest(jsonRequest) | ||
|
||
if request.Name == "a" { | ||
response.Num = 1 | ||
fmt.Fprint(w, buildResponse(response)) | ||
return | ||
} | ||
|
||
response.Num = 2 | ||
fmt.Fprint(w, buildResponse(response)) | ||
} | ||
|
||
func buildRequest(jsonRequest []byte) Request { | ||
var request Request | ||
|
||
json.Unmarshal(jsonRequest, &request) | ||
|
||
return request | ||
} | ||
|
||
func buildResponse(response Response) string { | ||
jsonResponse, _ := json.Marshal(response) | ||
|
||
return string(jsonResponse) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.