Skip to content

Commit

Permalink
chore: update isSQLErr
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Jan 15, 2024
1 parent 1defdc2 commit 72e0fd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions controllers/atlasschema_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package controllers
import (
"bytes"
"context"
"errors"
"fmt"
"net/url"
"os"
Expand All @@ -34,7 +35,7 @@ import (
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -579,7 +580,7 @@ func (m *mockClient) Get(ctx context.Context, key client.ObjectKey, obj client.O
// retrieve the object from the state map
o, ok := m.state[key]
if !ok {
return errors.NewNotFound(schema.GroupResource{
return kerr.NewNotFound(schema.GroupResource{
Group: obj.GetObjectKind().GroupVersionKind().Group,
}, key.Name)
}
Expand Down Expand Up @@ -657,7 +658,7 @@ func TestMock(t *testing.T) {
err := tt.k8s.Get(context.Background(), client.ObjectKey{
Name: "non-existent",
}, &d)
require.True(t, errors.IsNotFound(err))
require.True(t, kerr.IsNotFound(err))
// Retrieve an existing object
err = tt.k8s.Get(context.Background(), client.ObjectKey{
Name: "test",
Expand Down Expand Up @@ -735,8 +736,7 @@ func events(r record.EventRecorder) []string {
// 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))
require.True(t, isSQLErr(fmt.Errorf(`sql/migrate: execute: %s`, m)))
require.True(t, isSQLErr(fmt.Errorf(`sql/migrate: %s`, m)))
require.True(t, isSQLErr(errors.New(`Error: read state from "schema.sql": executing statement: "bad sql;": near "bad": syntax error`)))
}
3 changes: 2 additions & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func isSQLErr(err error) bool {
if err == nil {
return false
}
return sqlErrRegex.MatchString(err.Error())
s := err.Error()
return strings.Contains(s, "executing statement:") || sqlErrRegex.MatchString(s)
}

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

0 comments on commit 72e0fd6

Please sign in to comment.