[ut] add test for pkg/probe/http/request.go

Signed-off-by: xin.li <xin.li@daocloud.io>
This commit is contained in:
xin.li 2022-12-12 23:11:09 +08:00
parent 0e19bbb916
commit 8848f848db

View File

@ -16,7 +16,13 @@ limitations under the License.
package http
import "testing"
import (
"net/http"
"reflect"
"testing"
v1 "k8s.io/api/core/v1"
)
func TestFormatURL(t *testing.T) {
testCases := []struct {
@ -38,3 +44,37 @@ func TestFormatURL(t *testing.T) {
}
}
}
func Test_v1HeaderToHTTPHeader(t *testing.T) {
tests := []struct {
name string
headerList []v1.HTTPHeader
want http.Header
}{
{
name: "not empty input",
headerList: []v1.HTTPHeader{
{Name: "Connection", Value: "Keep-Alive"},
{Name: "Content-Type", Value: "text/html"},
{Name: "Accept-Ranges", Value: "bytes"},
},
want: http.Header{
"Connection": {"Keep-Alive"},
"Content-Type": {"text/html"},
"Accept-Ranges": {"bytes"},
},
},
{
name: "empty input",
headerList: []v1.HTTPHeader{},
want: http.Header{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := v1HeaderToHTTPHeader(tt.headerList); !reflect.DeepEqual(got, tt.want) {
t.Errorf("v1HeaderToHTTPHeader() = %v, want %v", got, tt.want)
}
})
}
}