-
Notifications
You must be signed in to change notification settings - Fork 1
/
httprequest_test.go
52 lines (40 loc) · 1.23 KB
/
httprequest_test.go
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
package biteship
import (
"fmt"
"github.com/stretchr/testify/assert"
"io"
"net/http"
"testing"
)
func TestCall_EmptySecret(t *testing.T) {
client := NewHttp()
err := client.Call(http.MethodPost, "https://someUrl.com", "", nil, nil)
assert.NotNil(t, err)
assert.Equal(t, err.Status, http.StatusUnauthorized)
assert.Equal(t, err.Message, "missing/invalid secret key")
}
func TestCall_InvalidURL(t *testing.T) {
var (
body io.Reader = nil
secret = "somesecret"
url = "wttps://invalid-url.com.com"
)
client := NewHttp()
err := client.Call(http.MethodPost, url, secret, body, nil)
assert.NotNil(t, err)
assert.Equal(t, err.Status, http.StatusInternalServerError)
assert.Equal(t, err.Error(), fmt.Sprintf(`Post "%s": unsupported protocol scheme "wttps"`, url))
}
func TestCall_UnknownUrl(t *testing.T) {
var (
body io.Reader = nil
secret = "somesecret"
url = "%escape"
)
client := NewHttp()
err := client.Call(http.MethodPost, url, secret, body, nil)
assert.NotNil(t, err)
assert.Equal(t, err.Status, http.StatusInternalServerError)
assert.Equal(t, err.Message, "Cannot create request")
assert.Equal(t, err.RawError, `parse "%escape": invalid URL escape "%es"`)
}