Skip to content

Commit

Permalink
coveralls test
Browse files Browse the repository at this point in the history
  • Loading branch information
abericyang@gmail.com committed Sep 20, 2019
1 parent 2f766bb commit 2f79760
Show file tree
Hide file tree
Showing 5 changed files with 340 additions and 241 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![GolangCI](https://golangci.com/badges/github.com/aberic/gnomon.svg)](https://golangci.com/r/github.com/aberic/gnomon)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4f11995425294f42aec6a207b8aab367)](https://www.codacy.com/manual/aberic/gnomon?utm_source=github.com&utm_medium=referral&utm_content=aberic/gnomon&utm_campaign=Badge_Grade)
[![Travis (.org)](https://img.shields.io/travis/aberic/gnomon.svg?label=build)](https://www.travis-ci.org/aberic/gnomon)
[![Coveralls github](https://img.shields.io/coveralls/github/aberic/gnomon.svg)](https://coveralls.io/github/aberic/gnomon?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/aberic/gnomon/badge.svg?branch=master)](https://coveralls.io/github/aberic/gnomon?branch=master)

# Gnomon
通用编写go应用的公共库。
Expand Down
123 changes: 0 additions & 123 deletions cryptos_test.go

This file was deleted.

75 changes: 75 additions & 0 deletions ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,78 @@ func TestIPCommon_Get(t *testing.T) {
}
}
}

func TestIPCommon_Get_XRealIP(t *testing.T) {
statusCode := http.StatusOK
server := mockServer()
defer server.Close()

client := &http.Client{}
req, _ := http.NewRequest("GET", server.URL, nil)
cookie1 := &http.Cookie{Name: "X-Xsrftoken", Value: "df41ba54db5011e89861002324e63af81", HttpOnly: true}
req.AddCookie(cookie1)

req.Header.Add("X-Real-IP", "192.168.0.1")
resp, err := client.Do(req)
if err != nil {
t.Fatal("\tShould be able to make the Get call.", ballotX, err)
}
t.Log("\t\tShould be able to make the Get call.", checkMark)
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode == statusCode {
t.Logf("\t\tShould receive a \"%d\" status, %v", statusCode, checkMark)
} else {
t.Errorf("\t\tShould receive a \"%d\" status. %v %v", statusCode, ballotX, resp.StatusCode)
}
}

func TestIPCommon_Get_XForwardedFor(t *testing.T) {
statusCode := http.StatusOK
server := mockServer()
defer server.Close()

client := &http.Client{}
req, _ := http.NewRequest("GET", server.URL, nil)
cookie1 := &http.Cookie{Name: "X-Xsrftoken", Value: "df41ba54db5011e89861002324e63af81", HttpOnly: true}
req.AddCookie(cookie1)

req.Header.Add("X-Forwarded-For", "192.168.0.2")
resp, err := client.Do(req)
if err != nil {
t.Fatal("\tShould be able to make the Get call.", ballotX, err)
}
t.Log("\t\tShould be able to make the Get call.", checkMark)
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode == statusCode {
t.Logf("\t\tShould receive a \"%d\" status, %v", statusCode, checkMark)
} else {
t.Errorf("\t\tShould receive a \"%d\" status. %v %v", statusCode, ballotX, resp.StatusCode)
}
}

func TestIPCommon_Get_XForwardedForIP6(t *testing.T) {
statusCode := http.StatusOK
server := mockServer()
defer server.Close()

client := &http.Client{}
req, _ := http.NewRequest("GET", server.URL, nil)
cookie1 := &http.Cookie{Name: "X-Xsrftoken", Value: "df41ba54db5011e89861002324e63af81", HttpOnly: true}
req.AddCookie(cookie1)

req.Header.Add("X-Forwarded-For", "::1")
resp, err := client.Do(req)
if err != nil {
t.Fatal("\tShould be able to make the Get call.", ballotX, err)
}
t.Log("\t\tShould be able to make the Get call.", checkMark)
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode == statusCode {
t.Logf("\t\tShould receive a \"%d\" status, %v", statusCode, checkMark)
} else {
t.Errorf("\t\tShould receive a \"%d\" status. %v %v", statusCode, ballotX, resp.StatusCode)
}
}
Loading

0 comments on commit 2f79760

Please sign in to comment.