Browse Source

Partial content is also ok

Piotr Czajkowski 4 years ago
parent
commit
8722f3a035
2 changed files with 22 additions and 1 deletions
  1. 1 1
      rest.go
  2. 21 0
      rest_test.go

+ 1 - 1
rest.go

@@ -31,7 +31,7 @@ func GET(url string) (*bytes.Buffer, error) {
 		return nil, fmt.Errorf("Error reading body: %v", err)
 		return nil, fmt.Errorf("Error reading body: %v", err)
 	}
 	}
 
 
-	if resp.StatusCode != http.StatusOK {
+	if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
 		return body, fmt.Errorf("Request unsuccessful: %v - %v", resp.Status, url)
 		return body, fmt.Errorf("Request unsuccessful: %v - %v", resp.Status, url)
 	}
 	}
 
 

+ 21 - 0
rest_test.go

@@ -78,6 +78,27 @@ func TestGET(t *testing.T) {
 	}
 	}
 }
 }
 
 
+func TestGET206(t *testing.T) {
+	expected := "Some text"
+	server := fakeServer(http.StatusPartialContent, expected)
+	defer server.Close()
+
+	data, err := GET(server.URL)
+	if data == nil {
+		t.Error("Data shouldn't be nil")
+	}
+
+	if err != nil {
+		t.Error(err)
+	}
+
+	result := data.String()
+
+	if expected != result {
+		t.Errorf("Wrong result, %v", result)
+	}
+}
+
 func TestGET404(t *testing.T) {
 func TestGET404(t *testing.T) {
 	expected := "Some text"
 	expected := "Some text"
 	server := fakeServer(http.StatusNotFound, expected)
 	server := fakeServer(http.StatusNotFound, expected)