| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package test |
| 18 |
|
| 19 |
import ( |
| 20 |
"fmt" |
| 21 |
"net/http" |
| 22 |
"strings" |
| 23 |
"testing" |
| 24 |
|
| 25 |
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/sample/sample" |
| 26 |
) |
| 27 |
|
| 28 |
const service = "http://localhost:8080" |
| 29 |
|
| 30 |
func TestSample(t *testing.T) { |
| 31 |
|
| 32 |
s := sample.NewClient(service, nil) |
| 33 |
|
| 34 |
{ |
| 35 |
message := "hello world" |
| 36 |
response, err := s.GetSample(message) |
| 37 |
if err != nil { |
| 38 |
t.Log("get sample failed") |
| 39 |
t.Fail() |
| 40 |
} |
| 41 |
if response.OK.Id != message || response.OK.Count != int32(len(message)) { |
| 42 |
t.Log(fmt.Sprintf("get sample received %+v", response.OK)) |
| 43 |
t.Fail() |
| 44 |
} |
| 45 |
if (response == nil) || (response.OK == nil) { |
| 46 |
t.Log(fmt.Sprintf("get sample failed %+v", response.OK)) |
| 47 |
t.Fail() |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
{ |
| 52 |
req, err := http.NewRequest("GET", service+"/unsupported", strings.NewReader("")) |
| 53 |
if err != nil { |
| 54 |
t.Log("bad request failed") |
| 55 |
return |
| 56 |
} |
| 57 |
resp, err := http.DefaultClient.Do(req) |
| 58 |
if err != nil { |
| 59 |
return |
| 60 |
} |
| 61 |
|
| 62 |
if resp.StatusCode != 404 { |
| 63 |
t.Log("bad request failed") |
| 64 |
t.Fail() |
| 65 |
} |
| 66 |
return |
| 67 |
} |
| 68 |
} |