aboutsummaryrefslogtreecommitdiffhomepage
path: root/http/client/response_test.go
blob: f3402a8096ec2b9a390dae8c16fc3f7d2c82f4e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

package client

import "testing"

func TestHasServerFailureWith200Status(t *testing.T) {
	r := &Response{StatusCode: 200}
	if r.HasServerFailure() {
		t.Error("200 is not a failure")
	}
}

func TestHasServerFailureWith404Status(t *testing.T) {
	r := &Response{StatusCode: 404}
	if !r.HasServerFailure() {
		t.Error("404 is a failure")
	}
}

func TestHasServerFailureWith500Status(t *testing.T) {
	r := &Response{StatusCode: 500}
	if !r.HasServerFailure() {
		t.Error("500 is a failure")
	}
}

func TestIsModifiedWith304Status(t *testing.T) {
	r := &Response{StatusCode: 304}
	if r.IsModified("etag", "lastModified") {
		t.Error("The resource should not be considered modified")
	}
}

func TestIsModifiedWithIdenticalEtag(t *testing.T) {
	r := &Response{StatusCode: 200, ETag: "etag"}
	if r.IsModified("etag", "lastModified") {
		t.Error("The resource should not be considered modified")
	}
}

func TestIsModifiedWithIdenticalLastModified(t *testing.T) {
	r := &Response{StatusCode: 200, LastModified: "lastModified"}
	if r.IsModified("etag", "lastModified") {
		t.Error("The resource should not be considered modified")
	}
}

func TestIsModifiedWithDifferentHeaders(t *testing.T) {
	r := &Response{StatusCode: 200, ETag: "some etag", LastModified: "some date"}
	if !r.IsModified("etag", "lastModified") {
		t.Error("The resource should be considered modified")
	}
}