GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#7)
by zuochao
09:46
created

response.Test_ParseFromHttpResponse   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
dl 0
loc 13
rs 9.8
c 0
b 0
f 0
nop 1
1
package response
2
3
import (
4
	"bytes"
5
	"errors"
6
	"io"
7
	"io/ioutil"
8
	"net/http"
9
	"strings"
10
	"testing"
11
12
	"github.com/stretchr/testify/assert"
13
)
14
15
func Test_ParseFromHttpResponse(t *testing.T) {
16
	r := &CommonResponse{}
17
	res := &http.Response{
18
		Body:       ioutil.NopCloser(bytes.NewReader([]byte(""))),
19
		StatusCode: 200,
20
		Header:     make(map[string][]string),
21
	}
22
	res.Header.Add("Server", "GitHub.com")
23
	r.ParseFromHttpResponse(res)
24
	assert.Equal(t, []byte{}, r.GetHttpContentBytes())
25
	assert.Equal(t, "", r.GetHttpContentString())
26
	assert.Equal(t, "GitHub.com", r.GetHttpHeaders()["Server"][0])
27
	assert.Equal(t, 200, r.GetHttpStatus())
28
}
29
30
func TestHookReadAll(t *testing.T) {
31
	fn := func(body io.Reader) (byt []byte, err error) {
32
		return nil, errors.New("hookReadAll")
33
	}
34
	result := hookReadAll(fn)
35
	byt, err := result(nil)
36
	assert.Nil(t, byt)
37
	assert.Equal(t, "hookReadAll", err.Error())
38
39
	originHookReadAll := hookReadAll
40
	hookReadAll = func(old func(body io.Reader) (byt []byte, err error)) func(body io.Reader) (byt []byte, err error) {
41
		return fn
42
	}
43
	defer func() {
44
		hookReadAll = originHookReadAll
45
	}()
46
	commonResponse := &CommonResponse{}
47
	httpResponse := &http.Response{
48
		Body: ioutil.NopCloser(strings.NewReader("creadential")),
49
	}
50
	err = commonResponse.ParseFromHttpResponse(httpResponse)
51
	assert.Equal(t, "hookReadAll", err.Error())
52
}
53