Merge pull request #114426 from my-git9/ut/request_

[UT] add test for pkg/probe/http/request.go
This commit is contained in:
Kubernetes Prow Robot 2023-03-09 21:33:45 -08:00 committed by GitHub
commit 78fe7c0dbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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)
}
})
}
}