mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2025-07-01 19:49:27 +00:00
New whatismydns feature (#29)
This commit is contained in:
10
internal/validator/uuid/uuid.go
Normal file
10
internal/validator/uuid/uuid.go
Normal file
@ -0,0 +1,10 @@
|
||||
package uuid
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func IsValid(u string) bool {
|
||||
_, err := uuid.Parse(u)
|
||||
return err == nil
|
||||
}
|
37
internal/validator/uuid/uuid_test.go
Normal file
37
internal/validator/uuid/uuid_test.go
Normal file
@ -0,0 +1,37 @@
|
||||
package uuid
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsValid(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
u string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "Valid UUID",
|
||||
u: "3b241101-e2bb-4255-8caf-4136c566a964",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Invalid UUID",
|
||||
u: "invalid-uuid",
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "Empty string",
|
||||
u: "",
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.True(t, IsValid(tt.u) == tt.want)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user