57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package webshared
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
const testBody = `{
|
|
"key": "value",
|
|
"more-key": 21
|
|
}`
|
|
|
|
var testBodyHash = []byte("22a5173da554010ea25f7d2ae34032a434c3a883a55d65f34c3413fdc555bed3")
|
|
|
|
func TestSignRequest(t *testing.T) {
|
|
// TODO: Implement tests
|
|
}
|
|
|
|
func Test_applyBodyHash_WithBody(t *testing.T) {
|
|
var headers = make(http.Header, 0)
|
|
digest := "SHA-256=" + string(testBodyHash)
|
|
applyBodyHash(headers, []byte(testBody))
|
|
headerDigest := headers.Get("Digest")
|
|
if headerDigest != digest {
|
|
t.Fatalf("digests didn't match: header \"%v\" != precalc \"%v\"", headerDigest, digest)
|
|
}
|
|
}
|
|
|
|
func TestNewRequest(t *testing.T) {
|
|
type args struct {
|
|
method string
|
|
url string
|
|
body io.Reader
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *http.Request
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NewRequest(tt.args.method, tt.args.url, tt.args.body)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("NewRequest() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("NewRequest() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|