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

[staticcheck] miscellaneous tidying #13892

Merged
merged 2 commits into from
Aug 31, 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
9 changes: 0 additions & 9 deletions go/mysql/flavor_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ func (flv *filePosFlavor) status(c *Conn) (replication.ReplicationStatus, error)
return replication.ParseFilePosReplicationStatus(resultMap)
}

func parseFilePosReplicationStatus(resultMap map[string]string) (replication.ReplicationStatus, error) {
status := replication.ParseReplicationStatus(resultMap)

status.Position = status.FilePosition
status.RelayLogPosition = status.RelayLogSourceBinlogEquivalentPosition

return status, nil
}

// primaryStatus is part of the Flavor interface.
func (flv *filePosFlavor) primaryStatus(c *Conn) (replication.PrimaryStatus, error) {
qr, err := c.ExecuteFetch("SHOW MASTER STATUS", 100, true /* wantfields */)
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func LaunchCluster(setupType int, streamMode string, stripes int, cDetails *Comp

// if streamMode is xbstream, add some additional args to test other xtrabackup flags
if streamMode == "xbstream" {
xtrabackupArgs = append(xtrabackupArgs, "--xtrabackup_prepare_flags", fmt.Sprintf("--use-memory=100M")) //nolint
xtrabackupArgs = append(xtrabackupArgs, "--xtrabackup_prepare_flags", "--use-memory=100M")
}

commonTabletArg = append(commonTabletArg, xtrabackupArgs...)
Expand Down
2 changes: 0 additions & 2 deletions go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"vitess.io/vitess/go/test/endtoend/onlineddl"
"vitess.io/vitess/go/test/endtoend/throttler"
"vitess.io/vitess/go/vt/schema"
throttlebase "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base"
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/throttlerapp"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
Expand All @@ -45,7 +44,6 @@ var (
clusterInstance *cluster.LocalProcessCluster
shards []cluster.Shard
vtParams mysql.ConnParams
httpClient = throttlebase.SetupHTTPClient(time.Second)

normalMigrationWait = 45 * time.Second
extendedMigrationWait = 60 * time.Second
Expand Down
3 changes: 0 additions & 3 deletions go/test/endtoend/onlineddl/vtctlutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ package onlineddl

import (
"testing"
"time"

"vitess.io/vitess/go/test/endtoend/cluster"

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

var throttlerConfigTimeout = 90 * time.Second

// CheckCancelAllMigrations cancels all pending migrations. There is no validation for affected migrations.
func CheckCancelAllMigrationsViaVtctl(t *testing.T, vtctlclient *cluster.VtctlClientProcess, keyspace string) {
cancelQuery := "alter vitess_migration cancel all"
Expand Down
19 changes: 0 additions & 19 deletions go/test/endtoend/onlineddl/vtgate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ package onlineddl
import (
"context"
"fmt"
"io"
"math"
"net/http"
"os"
"testing"
"time"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/schema"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/throttlerapp"
Expand Down Expand Up @@ -372,22 +369,6 @@ func WaitForThrottledTimestamp(t *testing.T, vtParams *mysql.ConnParams, uuid st
return
}

func getHTTPBody(url string) string {
resp, err := http.Get(url)
if err != nil {
log.Infof("http Get returns %+v", err)
return ""
}
if resp.StatusCode != 200 {
log.Infof("http Get returns status %d", resp.StatusCode)
return ""
}
respByte, _ := io.ReadAll(resp.Body)
defer resp.Body.Close()
body := string(respByte)
return body
}

// ValidateSequentialMigrationIDs validates that schem_migrations.id column, which is an AUTO_INCREMENT, does
// not have gaps
func ValidateSequentialMigrationIDs(t *testing.T, vtParams *mysql.ConnParams, shards []cluster.Shard) {
Expand Down
2 changes: 0 additions & 2 deletions go/test/endtoend/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ var (
hostname = "localhost"
keyspaceName = "ks"
shardName = "0"
dbName = "vt_ks"
mysqlUsers = []string{"vt_dba", "vt_app", "vt_appdebug", "vt_repl", "vt_filtered"}
mysqlPassword = "VtDbaPass"
vtgateUser = "vtgate_user"
vtgatePassword = "password123"
Expand Down
12 changes: 0 additions & 12 deletions go/test/endtoend/vreplication/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -537,17 +536,6 @@ func getDebugVar(t *testing.T, port int, varPath []string) (string, error) {
return string(val), nil
}

func getDebugVars(t *testing.T, port int) map[string]any {
out := map[string]any{}
response, err := http.Get(fmt.Sprintf("http://localhost:%d/debug/vars", port))
if err != nil {
return out
}
defer response.Body.Close()
_ = json.NewDecoder(response.Body).Decode(&out)
return out
}

func confirmWorkflowHasCopiedNoData(t *testing.T, targetKS, workflow string) {
timer := time.NewTimer(defaultTimeout)
defer timer.Stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ type workflow struct {
fromKeyspace string
toKeyspace string
typ string
tables []string
tc *vrepTestCase
options *workflowOptions
}

type vrepTestCase struct {
testName string
t *testing.T
cellNames []string
defaultCellName string
vtgateConn *mysql.Conn
keyspaces map[string]*keyspace
Expand Down
26 changes: 0 additions & 26 deletions go/test/endtoend/vreplication/vdiff_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"

"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/log"
vdiff2 "vitess.io/vitess/go/vt/vttablet/tabletmanager/vdiff"
"vitess.io/vitess/go/vt/wrangler"
Expand Down Expand Up @@ -224,30 +222,6 @@ func encodeString(in string) string {
return buf.String()
}

// updateTableStats runs ANALYZE TABLE on each table involved in the workflow.
// You should execute this if you leverage table information from e.g.
// information_schema.tables in your test.
func updateTableStats(t *testing.T, tablet *cluster.VttabletProcess, tables string) {
dbName := "vt_" + tablet.Keyspace
tableList := strings.Split(strings.TrimSpace(tables), ",")
if len(tableList) == 0 {
// we need to get all of the tables in the keyspace
res, err := tablet.QueryTabletWithDB("show tables", dbName)
require.NoError(t, err)
for _, row := range res.Rows {
tableList = append(tableList, row[0].String())
}
}
for _, table := range tableList {
table = strings.TrimSpace(table)
if table != "" {
res, err := tablet.QueryTabletWithDB(fmt.Sprintf(sqlAnalyzeTable, sqlescape.EscapeID(table)), dbName)
require.NoError(t, err)
require.Equal(t, 1, len(res.Rows))
}
}
}

// generateMoreCustomers creates additional test data for better tests
// when needed.
func generateMoreCustomers(t *testing.T, keyspace string, numCustomers int64) {
Expand Down
2 changes: 0 additions & 2 deletions go/test/endtoend/vreplication/vreplication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,6 @@ func TestCellAliasVreplicationWorkflow(t *testing.T) {
shardCustomer(t, true, []*Cell{cell1, cell2}, "alias", false)
}

var queryErrorCount int64

// testVStreamFrom confirms that the "vstream * from" endpoint is serving data
func testVStreamFrom(t *testing.T, table string, expectedRowCount int) {
ctx := context.Background()
Expand Down
10 changes: 0 additions & 10 deletions go/test/endtoend/vtgate/queries/random/query_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ func newSelectGenerator(r *rand.Rand, genConfig sqlparser.ExprGeneratorConfig, m
}
}

// getColumnName returns tableName.name (if tableName is nonempty), otherwise name
func (c *column) getColumnName() string {
var columnName string
if c.tableName != "" {
columnName += c.tableName + "."
}

return columnName + c.name
}

// getASTExpr returns the AST representation of a column
func (c *column) getASTExpr() sqlparser.Expr {
return sqlparser.NewColNameWithQualifier(c.name, sqlparser.NewTableName(c.tableName))
Expand Down
16 changes: 0 additions & 16 deletions go/tools/asthelpergen/copy_on_rewrite_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,6 @@ func (c *cowGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI)
return nil
}

func (c *cowGen) copySliceElement(t types.Type, elType types.Type, spi generatorSPI) jen.Code {
if !isNamed(t) && isBasic(elType) {
// copy(res, n)
return jen.Id("copy").Call(jen.Id("res"), jen.Id("n"))
}

// for i := range n {
// res[i] = CloneAST(x)
// }
spi.addType(elType)

return jen.For(jen.List(jen.Id("i"), jen.Id("x"))).Op(":=").Range().Id("n").Block(
jen.Id("res").Index(jen.Id("i")).Op("=").Add(c.readValueOfType(elType, jen.Id("x"), spi)),
)
}

func ifNotNil(id string, stmts ...jen.Code) *jen.Statement {
return jen.If(jen.Id(id).Op("!=").Nil()).Block(stmts...)
}
Expand Down
10 changes: 0 additions & 10 deletions go/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"strings"
"testing"

"github.com/spf13/viper"
Expand Down Expand Up @@ -104,15 +103,6 @@ func (f *fakeTracer) Close() error {
panic("implement me")
}

func (f *fakeTracer) assertNoSpanWith(t *testing.T, substr string) {
t.Helper()
for _, logLine := range f.log {
if strings.Contains(logLine, substr) {
t.Fatalf("expected to not find [%v] but found it in [%v]", substr, logLine)
}
}
}

type mockSpan struct {
tracer *fakeTracer
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/mysqlctl/tmutils/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestSchemaDiff(t *testing.T) {
})

testDiff(t, sd4, sd5, "sd4", "sd5", []string{
fmt.Sprintf("schemas differ on table type for table table2:\nsd4: VIEW\n differs from:\nsd5: BASE TABLE"), //nolint
"schemas differ on table type for table table2:\nsd4: VIEW\n differs from:\nsd5: BASE TABLE",
})

sd1.DatabaseSchema = "CREATE DATABASE {{.DatabaseName}}"
Expand Down
8 changes: 4 additions & 4 deletions go/vt/sqlparser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestSetAutocommitON(t *testing.T) {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if "on" != v.Val {
if v.Val != "on" {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
Expand All @@ -286,7 +286,7 @@ func TestSetAutocommitON(t *testing.T) {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if "on" != v.Val {
if v.Val != "on" {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
Expand All @@ -313,7 +313,7 @@ func TestSetAutocommitOFF(t *testing.T) {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if "off" != v.Val {
if v.Val != "off" {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
Expand All @@ -338,7 +338,7 @@ func TestSetAutocommitOFF(t *testing.T) {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if "off" != v.Val {
if v.Val != "off" {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6195,7 +6195,7 @@ func testFile(t *testing.T, filename, tempDir string) {
if fail && tempDir != "" {
gotFile := fmt.Sprintf("%s/%s", tempDir, filename)
_ = os.WriteFile(gotFile, []byte(strings.TrimSpace(expected.String())+"\n"), 0644)
fmt.Println(fmt.Sprintf("Errors found in parse tests. If the output is correct, run `cp %s/* testdata/` to update test expectations", tempDir)) // nolint
fmt.Printf("Errors found in parse tests. If the output is correct, run `cp %s/* testdata/` to update test expectations\n", tempDir)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/precedence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestRandom(t *testing.T) {
// The idea is to generate random queries, and pass them through the parser and then the unparser, and one more time. The result of the first unparse should be the same as the second result.
seed := time.Now().UnixNano()
r := rand.New(rand.NewSource(seed))
fmt.Println(fmt.Sprintf("seed is %d", seed)) // nolint
fmt.Printf("seed is %d\n", seed)
g := NewGenerator(r, 5)
endBy := time.Now().Add(1 * time.Second)

Expand Down
2 changes: 1 addition & 1 deletion go/vt/throttler/max_replication_lag_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (m *MaxReplicationLagModule) decreaseAndGuessRate(r *result, now time.Time,

if replicationLagChange == equal {
// The replication lag did not change. Keep going at the current rate.
r.Reason = fmt.Sprintf("did not decrease the rate because the lag did not change (assuming a 1s error margin)") // nolint
r.Reason = "did not decrease the rate because the lag did not change (assuming a 1s error margin)"
return
}

Expand Down
3 changes: 1 addition & 2 deletions go/vt/topo/consultopo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package consultopo

import (
"encoding/json"
"fmt"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -90,7 +89,7 @@ func getClientCreds() (creds map[string]*ClientAuthCred, err error) {
}

if err := json.Unmarshal(data, &creds); err != nil {
err = vterrors.Wrapf(err, fmt.Sprintf("Error parsing consul_auth_static_file")) //nolint
err = vterrors.Wrapf(err, "Error parsing consul_auth_static_file")
return creds, err
}
return creds, nil
Expand Down
14 changes: 0 additions & 14 deletions go/vt/vtadmin/cluster/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ func (cc *mockClientConn) assertUpdateWithin(t testing.TB, timeout time.Duration
}
}

func (cc *mockClientConn) assertErrorReportedWithin(t testing.TB, timeout time.Duration, msgAndArgs ...any) bool {
t.Helper()

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

select {
case <-ctx.Done():
return assert.Fail(t, "failed to receive reported error", "did not receive reported error within %v: %s", timeout, ctx.Err())
case actual := <-cc.errors:
return assert.Error(t, actual, msgAndArgs...)
}
}

func (cc *mockClientConn) UpdateState(state grpcresolver.State) error {
select {
case <-cc.ctx.Done():
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtorc/discovery/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ func (q *Queue) startMonitoring() {
}
}

// Stop monitoring the queue
func (q *Queue) stopMonitoring() {
q.done <- struct{}{}
}

// do a check of the entries in the queue, both those active and queued
func (q *Queue) collectStatistics() {
q.Lock()
Expand Down
Loading