Skip to content

Commit

Permalink
cherry pick of 15184 (#4353)
Browse files Browse the repository at this point in the history
  • Loading branch information
planetscale-actions-bot authored Feb 10, 2024
1 parent d334754 commit 2a412d1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 359 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ linters-settings:
disable: # not supported when using Generics in 1.18
- nilness
- unusedwrite
- loopclosure # fixed in go1.22

linters:
disable-all: true
Expand Down
2 changes: 0 additions & 2 deletions go/vt/mysqlctl/mysqlctlproto/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ func TestBackupHandleToProto(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.bh.testname(), func(t *testing.T) {
t.Parallel()

Expand Down
42 changes: 14 additions & 28 deletions go/vt/sqlparser/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package sqlparser

import (
"fmt"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stretchr/testify/assert"
"vitess.io/vitess/go/vt/sysvars"

querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/sysvars"
)

func TestSplitComments(t *testing.T) {
Expand Down Expand Up @@ -143,15 +142,9 @@ func TestSplitComments(t *testing.T) {
gotSQL, gotComments := SplitMarginComments(testCase.input)
gotLeadingComments, gotTrailingComments := gotComments.Leading, gotComments.Trailing

if gotSQL != testCase.outSQL {
t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL)
}
if gotLeadingComments != testCase.outLeadingComments {
t.Errorf("test input: '%s', got LeadingComments\n%+v, want\n%+v", testCase.input, gotLeadingComments, testCase.outLeadingComments)
}
if gotTrailingComments != testCase.outTrailingComments {
t.Errorf("test input: '%s', got TrailingComments\n%+v, want\n%+v", testCase.input, gotTrailingComments, testCase.outTrailingComments)
}
assert.Equal(t, testCase.outSQL, gotSQL, "SQL mismatch")
assert.Equal(t, testCase.outLeadingComments, gotLeadingComments, "LeadingComments mismatch")
assert.Equal(t, testCase.outTrailingComments, gotTrailingComments, "TrailingCommints mismatch")
})
}
}
Expand Down Expand Up @@ -225,10 +218,7 @@ a`,
}}
for _, testCase := range testCases {
gotSQL := StripLeadingComments(testCase.input)

if gotSQL != testCase.outSQL {
t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL)
}
assert.Equal(t, testCase.outSQL, gotSQL)
}
}

Expand All @@ -254,10 +244,8 @@ func TestExtractMysqlComment(t *testing.T) {
}}
for _, testCase := range testCases {
gotVersion, gotSQL := ExtractMysqlComment(testCase.input)
assert.Equal(t, testCase.outVersion, gotVersion, "version mismatch")

if gotVersion != testCase.outVersion {
t.Errorf("test input: '%s', got version\n%+v, want\n%+v", testCase.input, gotVersion, testCase.outVersion)
}
if gotSQL != testCase.outSQL {
t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL)
}
Expand Down Expand Up @@ -369,9 +357,8 @@ func TestExtractCommentDirectives(t *testing.T) {
require.Nil(t, vals)
return
}
if !reflect.DeepEqual(vals.m, testCase.vals) {
t.Errorf("test input: '%v', got vals %T:\n%+v, want %T\n%+v", testCase.input, vals, vals, testCase.vals, testCase.vals)
}

assert.Equal(t, testCase.vals, vals.m)
})
}
})
Expand Down Expand Up @@ -543,17 +530,16 @@ func TestGetPriorityFromStatement(t *testing.T) {

parser := NewTestParser()
for _, testCase := range testCases {
theThestCase := testCase
t.Run(theThestCase.query, func(t *testing.T) {
t.Run(testCase.query, func(t *testing.T) {
t.Parallel()
stmt, err := parser.Parse(theThestCase.query)
stmt, err := parser.Parse(testCase.query)
assert.NoError(t, err)
actualPriority, actualError := GetPriorityFromStatement(stmt)
if theThestCase.expectedError != nil {
assert.ErrorIs(t, actualError, theThestCase.expectedError)
if testCase.expectedError != nil {
assert.ErrorIs(t, actualError, testCase.expectedError)
} else {
assert.NoError(t, err)
assert.Equal(t, theThestCase.expectedPriority, actualPriority)
assert.Equal(t, testCase.expectedPriority, actualPriority)
}
})
}
Expand Down
Loading

0 comments on commit 2a412d1

Please sign in to comment.