Skip to content

Commit c01e0da

Browse files
committed
test: add unit tests for extractTypeName function
1 parent 1229547 commit c01e0da

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

pkg/migration/file_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,38 @@ func TestMigrationFile(t *testing.T) {
120120
})
121121
}
122122

123+
func TestExtractTypeName(t *testing.T) {
124+
t.Run("extracts type name from standard error message", func(t *testing.T) {
125+
result := extractTypeName(`type "ltree" does not exist`)
126+
assert.Equal(t, "ltree", result)
127+
})
128+
129+
t.Run("extracts schema-qualified type name", func(t *testing.T) {
130+
result := extractTypeName(`type "extensions.ltree" does not exist`)
131+
assert.Equal(t, "extensions.ltree", result)
132+
})
133+
134+
t.Run("extracts type with underscores", func(t *testing.T) {
135+
result := extractTypeName(`type "my_custom_type" does not exist`)
136+
assert.Equal(t, "my_custom_type", result)
137+
})
138+
139+
t.Run("returns empty string for non-matching message", func(t *testing.T) {
140+
result := extractTypeName(`column "name" does not exist`)
141+
assert.Equal(t, "", result)
142+
})
143+
144+
t.Run("returns empty string for empty message", func(t *testing.T) {
145+
result := extractTypeName("")
146+
assert.Equal(t, "", result)
147+
})
148+
149+
t.Run("handles type names with numbers", func(t *testing.T) {
150+
result := extractTypeName(`type "type123" does not exist`)
151+
assert.Equal(t, "type123", result)
152+
})
153+
}
154+
123155
func TestIsSchemaQualified(t *testing.T) {
124156
assert.True(t, IsSchemaQualified("extensions.ltree"))
125157
assert.True(t, IsSchemaQualified("public.my_type"))

0 commit comments

Comments
 (0)