(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestRigidHandle(t *testing.T) { |
| 76 | ts := httptest.NewServer(HTTPHandler{Handler: HandlerFunc(simpleHandle), Methods: []string{"POST"}}) |
| 77 | defer ts.Close() |
| 78 | |
| 79 | // Response to compliment |
| 80 | obj := map[string]interface{}{} |
| 81 | obj["compliment"] = "it's good" |
| 82 | resp, body := post(t, obj, ts) |
| 83 | |
| 84 | if resp.StatusCode != http.StatusOK { |
| 85 | t.Errorf("Test expected 200, have %d", resp.StatusCode) |
| 86 | } |
| 87 | |
| 88 | message := new(Response) |
| 89 | err := json.Unmarshal(body, message) |
| 90 | if err != nil { |
| 91 | t.Errorf("failed to read response body: %v", err) |
| 92 | t.Fatal("returned:", message) |
| 93 | } |
| 94 | |
| 95 | if message.Result != ty { |
| 96 | t.Fatal("Wrong response") |
| 97 | } |
| 98 | |
| 99 | // Response to critique |
| 100 | obj = map[string]interface{}{} |
| 101 | obj["critique"] = "it's bad" |
| 102 | resp, body = post(t, obj, ts) |
| 103 | |
| 104 | if resp.StatusCode != http.StatusOK { |
| 105 | t.Errorf("Test expected 200, have %d", resp.StatusCode) |
| 106 | } |
| 107 | |
| 108 | message = new(Response) |
| 109 | err = json.Unmarshal(body, message) |
| 110 | if err != nil { |
| 111 | t.Errorf("failed to read response body: %v", err) |
| 112 | t.Fatal("returned:", message) |
| 113 | } |
| 114 | |
| 115 | if message.Result != ty { |
| 116 | t.Fatal("Wrong response") |
| 117 | } |
| 118 | |
| 119 | // reject mixed review |
| 120 | obj = map[string]interface{}{} |
| 121 | obj["critique"] = "it's OK" |
| 122 | obj["compliment"] = "it's not bad" |
| 123 | resp, _ = post(t, obj, ts) |
| 124 | |
| 125 | if resp.StatusCode != http.StatusBadRequest { |
| 126 | t.Errorf("Test expected 400, have %d", resp.StatusCode) |
| 127 | } |
| 128 | |
| 129 | // reject empty review |
| 130 | obj = map[string]interface{}{} |
| 131 | resp, _ = post(t, obj, ts) |
| 132 |
nothing calls this directly
no test coverage detected
searching dependent graphs…