Skip to content

Commit

Permalink
tests: add more testcases for invalid uuid inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwingopalsamy committed Dec 26, 2024
1 parent 0f275bc commit 7b52e05
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions uuidv8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,28 +723,43 @@ func TestUUIDv8_Scan_EdgeCases(t *testing.T) {

func TestFromString_InvalidInputs(t *testing.T) {
tests := []string{
"123", // Too short
"123e4567e89b12d3a4564266141740000000", // Too long
"123e4567e89b12d3a45642661417400g", // Invalid character
"123e-4567-e89b-12d3-a456-426614174000", // Misplaced dashes
"123", // Too short
"123e4567e89b12d3a4564266141740000000", // Too long
"123e4567e89b12d3a45642661417400g", // Invalid character
"123e-4567-e89b-12d3-a456-426614174000", // Misplaced dashes
"123e4567-e89b-12d3-a456-426614174000-", // Extra dash at the end
"--123e4567-e89b-12d3-a456-426614174000", // Extra dash at the start
"123e4567-e89b-12d3-a456-42-6614174000", // Randomly placed dash
"------------------------------------", // 36 dashes
"9a3d4049-0e2c-8080-0102-030405060000", // Valid UUID with dashes
}

for _, input := range tests {
t.Run("Invalid UUID "+input, func(t *testing.T) {
t.Run("Testing UUID: "+input, func(t *testing.T) {
_, err := uuidv8.FromString(input)
if err == nil {
t.Errorf("Expected error, got nil for input: %s", input)
// The last case is valid; others should fail
if input == "9a3d4049-0e2c-8080-0102-030405060000" {
if err != nil {
t.Errorf("Expected valid UUID but got error for input: %s", input)
}
} else {
if err == nil {
t.Errorf("Expected error, got nil for input: %s", input)
}
}
})
}
}

func TestFromStringOrNil_InvalidInputs(t *testing.T) {
tests := []string{
"123", // Too short
"123e4567e89b12d3a4564266141740000000", // Too long
"123e4567e89b12d3a45642661417400g", // Invalid character
"", // Empty string
"123", // Too short
"123e4567e89b12d3a4564266141740000000", // Too long
"123e4567e89b12d3a45642661417400g", // Invalid character
"", // Empty string
"123e4567-e89b-12d3-a456-426614174000-", // Extra dash at the end
"--123e4567-e89b-12d3-a456-426614174000", // Extra dash at the start
"123e4567-e89b-12d3-a456-42-6614174000", // Randomly placed dash
}

for _, input := range tests {
Expand All @@ -759,10 +774,14 @@ func TestFromStringOrNil_InvalidInputs(t *testing.T) {

func TestIsValidUUIDv8_InvalidUUIDs(t *testing.T) {
invalidUUIDs := []string{
"123", // Too short
"123e4567e89b12d3a4564266141740000000", // Too long
"123e4567e89b12d3a45642661417400g", // Invalid character
"", // Empty string
"123", // Too short
"123e4567e89b12d3a4564266141740000000", // Too long
"123e4567e89b12d3a45642661417400g", // Invalid character
"", // Empty string
"123e4567-e89b-12d3-a456-426614174000-", // Extra dash at the end
"--123e4567-e89b-12d3-a456-426614174000", // Extra dash at the start
"123e4567-e89b-12d3-a456-42-6614174000", // Randomly placed dash

}

for _, uuid := range invalidUUIDs {
Expand Down

0 comments on commit 7b52e05

Please sign in to comment.