(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func TestCleverHandle(t *testing.T) { |
| 146 | ts := httptest.NewServer(HTTPHandler{Handler: HandlerFunc(cleverHandle), Methods: []string{"POST"}}) |
| 147 | defer ts.Close() |
| 148 | |
| 149 | // Response ty to compliment |
| 150 | obj := map[string]interface{}{} |
| 151 | obj["compliment"] = "it's good" |
| 152 | resp, body := post(t, obj, ts) |
| 153 | |
| 154 | if resp.StatusCode != http.StatusOK { |
| 155 | t.Errorf("Test expected 200, have %d", resp.StatusCode) |
| 156 | } |
| 157 | |
| 158 | message := new(Response) |
| 159 | err := json.Unmarshal(body, message) |
| 160 | if err != nil { |
| 161 | t.Errorf("failed to read response body: %v", err) |
| 162 | t.Fatal("returned:", message) |
| 163 | } |
| 164 | |
| 165 | if message.Result != ty { |
| 166 | t.Fatal("Wrong response") |
| 167 | } |
| 168 | |
| 169 | // Response deny to critique |
| 170 | obj = map[string]interface{}{} |
| 171 | obj["critique"] = "it's bad" |
| 172 | resp, body = post(t, obj, ts) |
| 173 | |
| 174 | if resp.StatusCode != http.StatusOK { |
| 175 | t.Errorf("Test expected 200, have %d", resp.StatusCode) |
| 176 | } |
| 177 | |
| 178 | message = new(Response) |
| 179 | err = json.Unmarshal(body, message) |
| 180 | if err != nil { |
| 181 | t.Errorf("failed to read response body: %v", err) |
| 182 | t.Fatal("returned:", message) |
| 183 | } |
| 184 | |
| 185 | if message.Result != deny { |
| 186 | t.Fatal("Wrong response") |
| 187 | } |
| 188 | |
| 189 | // Be polite to mixed review |
| 190 | obj = map[string]interface{}{} |
| 191 | obj["critique"] = "it's OK" |
| 192 | obj["compliment"] = "it's not bad" |
| 193 | _, body = post(t, obj, ts) |
| 194 | |
| 195 | message = new(Response) |
| 196 | err = json.Unmarshal(body, message) |
| 197 | if err != nil { |
| 198 | t.Errorf("failed to read response body: %v", err) |
| 199 | t.Fatal("returned:", message) |
| 200 | } |
| 201 | |
| 202 | if message.Result != ty { |
nothing calls this directly
no test coverage detected
searching dependent graphs…