-
Notifications
You must be signed in to change notification settings - Fork 32
/
server_test.go
42 lines (30 loc) · 1.43 KB
/
server_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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseMinilockID(t *testing.T) {
// request without header returns Error
req := httptest.NewRequest(http.MethodGet, "/", nil)
mID, keypair, err := parseMinilockID(req)
assert.Equal(t, "", mID, fmt.Sprintf("mID was not an empty string: %v\n", mID))
assert.Nil(t, keypair, fmt.Sprintf("keypair was unexpectedly not nil: %v\n", keypair))
assert.NotNil(t, err, fmt.Sprintf("err was unexpectedly nil: %v\n", err))
// request with invalid header value returns Error
invalidMiniLockId := "2aSQkrU5hp"
req.Header.Set("X-Minilock-Id", invalidMiniLockId)
mID, keypair, err = parseMinilockID(req)
assert.Equal(t, "", mID, fmt.Sprintf("mID was not an empty string: %v\n", mID))
assert.Nil(t, keypair, fmt.Sprintf("keypair was unexpectedly not nil: %v\n", keypair))
assert.NotNil(t, err, fmt.Sprintf("err was unexpectedly nil: %v\n", err))
// request with valid header value returns value, nil Error
validMiniLockId := "s9dDgRKVWvnkpifRXiSgFGj9QLgq1BZ3qvzCsnxPFDrQG"
req.Header.Set("X-Minilock-Id", validMiniLockId)
mID, keypair, err = parseMinilockID(req)
assert.Equal(t, validMiniLockId, mID, fmt.Sprintf("mID was unexpected an empty string: %v\n", mID))
assert.NotNil(t, keypair, fmt.Sprintf("keypair was unexpectedly nil: %v\n", keypair))
assert.Nil(t, err, fmt.Sprintf("err was unexpectedly not nil: %v\n", err))
}