Add some tests

This commit is contained in:
edoardottt
2022-09-11 21:14:27 +02:00
parent 29f4cbfb0e
commit 3176039f46
+41
View File
@@ -130,3 +130,44 @@ func TestGetRootHost(t *testing.T) {
})
}
}
func TestHasProtocol(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{
name: "empty string",
input: "",
want: false,
},
{
name: "no protocol",
input: "ciao.com",
want: false,
},
{
name: "no protocol2",
input: "ciao.ciao.com",
want: false,
},
{
name: "ok1",
input: "http://sub.edoardottt.com/ciao?id=1",
want: true,
},
{
name: "ok2",
input: "ftp://sub.edoardottt.com/://ciao",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := utils.HasProtocol(tt.input); !reflect.DeepEqual(got, tt.want) {
t.Errorf("HasProtocol() = %v, want %v", got, tt.want)
}
})
}
}