Browse Source

Check the status

Piotr Czajkowski 3 years ago
parent
commit
0136fa2c68
2 changed files with 18 additions and 0 deletions
  1. 5 0
      tm.go
  2. 13 0
      tm_test.go

+ 5 - 0
tm.go

@@ -44,6 +44,11 @@ func (app *Application) getTMs(language string) []TM {
 		return app.getTMs(language)
 	}
 
+	if resp.StatusCode != http.StatusOK {
+		log.Printf("Problem getting TMs (%s)!", resp.Status)
+		return results
+	}
+
 	err := jsonDecoder(resp.Body, &results)
 	if err != nil {
 		log.Printf("Error decoding TM results: %s", err)

+ 13 - 0
tm_test.go

@@ -39,3 +39,16 @@ func TestGetTMs(t *testing.T) {
 		t.Fatalf("Something went wrong while reading TMs!\n%v", tms)
 	}
 }
+
+func TestGetTMsWrongStatus(t *testing.T) {
+	server := fakeServer(http.StatusBadRequest, "")
+	defer server.Close()
+
+	var app Application
+	app.setBaseURL(server.URL)
+
+	tms := app.getTMs("")
+	if len(tms) != 0 {
+		t.Fatal("There should be no TMs!")
+	}
+}