mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-13 18:53:44 +08:00
Feature/cover unit test (#81)
This commit is contained in:
@@ -1,28 +1,30 @@
|
||||
package validUtil
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsURL(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
input string
|
||||
expected bool
|
||||
}{
|
||||
{"https://www.google.com", true},
|
||||
{"http://example.com", true},
|
||||
{"https://www.example.com/path?query=string", true},
|
||||
{"ftp://ftp.example.com", false},
|
||||
{"invalid url", false},
|
||||
{"www.example.com", false},
|
||||
{"example.com", false},
|
||||
{"http://", false},
|
||||
{"有效网址1", "https://www.google.com", true},
|
||||
{"有效网址2", "http://example.com", true},
|
||||
{"有效网址3", "https://www.example.com/path?query=string", true},
|
||||
{"无效网址1", "ftp://ftp.example.com", false},
|
||||
{"无效网址2", "invalid url", false},
|
||||
{"无效网址3", "www.example.com", false},
|
||||
{"无效网址4", "example.com", false},
|
||||
{"无效网址5", "http://", false},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
result := IsURL(tc.input)
|
||||
if result != tc.expected {
|
||||
t.Errorf("Expected IsURL(%q) to be %v, but got %v", tc.input, tc.expected, result)
|
||||
}
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res := IsURL(tc.input)
|
||||
assert.Equal(t, tc.expected, res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user