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