test: Improve coverage for Endpoint.Type()

This commit is contained in:
TwiN 2022-09-01 21:09:36 -04:00
parent 52d7cb6f04
commit 4857b43771

View File

@ -24,53 +24,72 @@ func TestEndpoint_IsEnabled(t *testing.T) {
} }
func TestEndpoint_Type(t *testing.T) { func TestEndpoint_Type(t *testing.T) {
type fields struct { type args struct {
URL string URL string
DNS *DNS DNS *DNS
} }
tests := []struct { tests := []struct {
fields fields args args
want EndpointType want EndpointType
}{{ }{
fields: fields{ {
URL: "1.1.1.1", args: args{
DNS: &DNS{ URL: "1.1.1.1",
QueryType: "A", DNS: &DNS{
QueryName: "example.com", QueryType: "A",
QueryName: "example.com",
},
}, },
want: EndpointTypeDNS,
}, },
want: EndpointTypeDNS, {
}, { args: args{
fields: fields{ URL: "tcp://127.0.0.1:6379",
URL: "tcp://127.0.0.1:6379", },
want: EndpointTypeTCP,
}, },
want: EndpointTypeTCP, {
}, { args: args{
fields: fields{ URL: "icmp://example.com",
URL: "icmp://example.com", },
want: EndpointTypeICMP,
}, },
want: EndpointTypeICMP, {
}, { args: args{
fields: fields{ URL: "starttls://smtp.gmail.com:587",
URL: "starttls://smtp.gmail.com:587", },
want: EndpointTypeSTARTTLS,
}, },
want: EndpointTypeSTARTTLS, {
}, { args: args{
fields: fields{ URL: "tls://example.com:443",
URL: "tls://example.com:443", },
want: EndpointTypeTLS,
}, },
want: EndpointTypeTLS, {
}, { args: args{
fields: fields{ URL: "https://twin.sh/health",
URL: "https://twin.sh/health", },
want: EndpointTypeHTTP,
}, },
want: EndpointTypeHTTP, {
}} args: args{
URL: "invalid://example.org",
},
want: EndpointTypeUNKNOWN,
},
{
args: args{
URL: "no-scheme",
},
want: EndpointTypeUNKNOWN,
},
}
for _, tt := range tests { for _, tt := range tests {
t.Run(string(tt.want), func(t *testing.T) { t.Run(string(tt.want), func(t *testing.T) {
endpoint := Endpoint{ endpoint := Endpoint{
URL: tt.fields.URL, URL: tt.args.URL,
DNS: tt.fields.DNS, DNS: tt.args.DNS,
} }
if got := endpoint.Type(); got != tt.want { if got := endpoint.Type(); got != tt.want {
t.Errorf("Endpoint.Type() = %v, want %v", got, tt.want) t.Errorf("Endpoint.Type() = %v, want %v", got, tt.want)