Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers: adapt to error message change for sql exec errs #124

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions controllers/atlasschema_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,13 @@ func events(r record.EventRecorder) []string {
}
}
}

// Versions after v0.17 of Atlas return a slightly more readable error message. This test
// ensures we support both formats.
func TestSQLErrRegression(t *testing.T) {
m := `executing statement "create table bar (id int)"`
e1 := fmt.Errorf(`sql/migrate: execute: %s`, m)
e2 := fmt.Errorf(`sql/migrate: %s`, m)
require.True(t, isSQLErr(e1))
require.True(t, isSQLErr(e2))
}
3 changes: 2 additions & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var (
}).
ParseFS(tmpls, "templates/*.tmpl"),
)
sqlErrRegex = regexp.MustCompile(`sql/migrate: (execute: )?executing statement`)
)

func getConfigMap(ctx context.Context, r client.Reader, ns string, ref *corev1.LocalObjectReference) (*corev1.ConfigMap, error) {
Expand Down Expand Up @@ -116,7 +117,7 @@ func isSQLErr(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), "sql/migrate: execute: executing statement")
return sqlErrRegex.MatchString(err.Error())
}

// isChecksumErr returns true if the error is a checksum error.
Expand Down
Loading