Added more tests and refactored exporter tests. Added code coverage badge.
This commit is contained in:
91
client/client_test.go
Normal file
91
client/client_test.go
Normal file
@ -0,0 +1,91 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetDefaultHeader(t *testing.T) {
|
||||
type args struct {
|
||||
header http.Header
|
||||
key string
|
||||
value string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want http.Header
|
||||
}{
|
||||
{
|
||||
name: "Simple",
|
||||
args: args{http.Header{}, "key", "value"},
|
||||
want: http.Header{"Key": []string{"value"}},
|
||||
},
|
||||
{
|
||||
name: "Dont Override",
|
||||
args: args{http.Header{"Key": []string{"value"}}, "key", "new value"},
|
||||
want: http.Header{"Key": []string{"value"}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := SetDefaultHeader(tt.args.header, tt.args.key, tt.args.value); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SetDefaultHeader() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertHeaderToMap(t *testing.T) {
|
||||
type args struct {
|
||||
header http.Header
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want map[string]interface{}
|
||||
}{
|
||||
{
|
||||
name: "Simple",
|
||||
args: args{http.Header{"Key": []string{"value"}}},
|
||||
want: map[string]interface{}{"Key": "value"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := ConvertHeaderToMap(tt.args.header); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ConvertHeaderToMap() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertMapToHeader(t *testing.T) {
|
||||
type args struct {
|
||||
m map[string]interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want http.Header
|
||||
}{
|
||||
{
|
||||
name: "Simple",
|
||||
args: args{map[string]interface{}{"Key": "value"}},
|
||||
want: http.Header{"Key": []string{"value"}},
|
||||
},
|
||||
{
|
||||
name: "Non standard key",
|
||||
args: args{map[string]interface{}{"key": "value"}},
|
||||
want: http.Header{"Key": []string{"value"}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := ConvertMapToHeader(tt.args.m); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ConvertMapToHeader() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user