Skip to content
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
446 changes: 172 additions & 274 deletions .golangci.yml

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
.DEFAULT_GOAL := test_and_build

REQUIRED_GO_VERSION := 1.23
GOLANGCI_LINT_VERSION := v1.64.6
GOLANGCI_LINT_VERSION := v2.0.2

# Determine the Go binary directory
GOBIN_DIR := $(or $(GOBIN), $(shell go env GOBIN))
ifeq ($(GOBIN_DIR),)
GOBIN_DIR := $(shell go env GOPATH)/bin
endif

COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date +%Y-%m-%dT%H:%M:%S)

test_and_build: test build

# Version check
Expand All @@ -28,7 +31,10 @@ default: check_version build

build:
@echo "Building vt..."
@go build -o vt ./go/vt
@go build -ldflags "\
-X github.com/vitessio/vt/go/cmd.CommitSha=$(COMMIT) \
-X github.com/vitessio/vt/go/cmd.BuildDate=$(DATE)" \
-o vt ./go/vt

test:
go test -v -count=1 ./go/...
Expand Down
1 change: 1 addition & 0 deletions go/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ func getRootCmd() *cobra.Command {
root.AddCommand(dbinfoCmd())
root.AddCommand(transactionsCmd())
root.AddCommand(planalyzeCmd())
root.AddCommand(versionCmd())
return root
}
1 change: 1 addition & 0 deletions go/cmd/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ func commonFlags(cmd *cobra.Command, cfg *vttester.Config) {
cmd.Flags().StringVar(&cfg.TraceFile, "trace-file", "", "Do a vexplain trace on all queries and store the output in the given file.")
cmd.Flags().BoolVar(&cfg.Sharded, "sharded", false, "Run all tests on a sharded keyspace and using auto-vschema. This cannot be used with either -vschema or -vtexplain-vschema.")
cmd.Flags().StringVar(&cfg.BackupDir, "backup-path", "", "Restore from backup before running the tester")
cmd.Flags().BoolVar(&cfg.Verbose, "verbose", false, "Print to stdout the queries that are being run.")
}
42 changes: 42 additions & 0 deletions go/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2025 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var (
//nolint:gochecknoglobals // This is set by the linker at build time.
CommitSha = "none" // default, overridden by ldflags

//nolint:gochecknoglobals // This is set by the linker at build time.
BuildDate = "unknown" // default, overridden by ldflags
)

func versionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Show the CLI version",
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("built on %s on git commit '%s'\n", BuildDate, CommitSha)
},
}
return cmd
}
2 changes: 1 addition & 1 deletion go/dbinfo/dbinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestDBInfoLoad(t *testing.T) {
"gtid_mode": "OFF",
"log_bin": "ON",
}
require.EqualValues(t, expected, si.GlobalVariables)
require.Equal(t, expected, si.GlobalVariables)
})
}

Expand Down
2 changes: 1 addition & 1 deletion go/planalyze/planalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func getPlanRes(err error, plan *engine.Plan) PlanComplexity {
case *engine.Delete:
rp = prim.RoutingParameters
case *engine.Insert:
if prim.InsertCommon.Opcode == engine.InsertUnsharded {
if prim.Opcode == engine.InsertUnsharded {
return PassThrough
}
return SimpleRouted
Expand Down
9 changes: 6 additions & 3 deletions go/tester/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func ExecuteTests(

for _, name := range cfg.Tests {
errReporter := s.NewReporterForFile(name)
if cfg.Verbose {
errReporter = &loggingReporter{inner: errReporter}
}
vTester := NewTester(name, errReporter, info, cfg.OLAP, info.vschema, vschemaF, factory, cfg.Loader)
err := vTester.Run()
if err != nil {
Expand Down Expand Up @@ -214,10 +217,10 @@ func generateShardRanges(numberOfShards int) []string {
start := i * step
end := (i + 1) * step

switch {
case i == 0:
switch i {
case 0:
ranges[i] = fmt.Sprintf("-%02x", end)
case i == numberOfShards-1:
case numberOfShards - 1:
ranges[i] = fmt.Sprintf("%02x-", start)
default:
ranges[i] = fmt.Sprintf("%02x-%02x", start, end)
Expand Down
64 changes: 64 additions & 0 deletions go/tester/logging_reporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2025 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tester

import "fmt"

type loggingReporter struct {
inner Reporter
}

var _ Reporter = (*loggingReporter)(nil)

func (l *loggingReporter) Errorf(format string, args ...interface{}) {
l.inner.Errorf(format, args...)
}

func (l *loggingReporter) FailNow() {
l.inner.FailNow()
}

func (l *loggingReporter) Helper() {
l.inner.Helper()
}

func (l *loggingReporter) AddTestCase(query string, lineNo int) {
fmt.Printf("Running query %q on line #%d\n", query, lineNo)
l.inner.AddTestCase(query, lineNo)
}

func (l *loggingReporter) EndTestCase() {
l.inner.EndTestCase()
}

func (l *loggingReporter) AddFailure(err error) {
fmt.Printf("Failure added: %s\n", err.Error())
l.inner.AddFailure(err)
}

func (l *loggingReporter) AddInfo(info string) {
fmt.Printf("Info: %s\n", info)
l.inner.AddInfo(info)
}

func (l *loggingReporter) Report() string {
return l.inner.Report()
}

func (l *loggingReporter) Failed() bool {
return l.inner.Failed()
}
2 changes: 1 addition & 1 deletion go/tester/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (e *FileReporter) createErrorFileFor() *os.File {
errorPath := path.Join(e.errorDir(), qc)
file, err := os.Create(errorPath)
exitIf(err, "creating error file")
_, err = file.WriteString(fmt.Sprintf("Error log for query on line %d:\n%s\n\n", e.currentQueryLineNum, e.currentQuery))
_, err = fmt.Fprintf(file, "Error log for query on line %d:\n%s\n\n", e.currentQueryLineNum, e.currentQuery)
exitIf(err, "writing to error file")

return file
Expand Down
3 changes: 2 additions & 1 deletion go/tester/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Config struct {
Tests []string
NumberOfShards int
Compare bool
Verbose bool

BackupDir string
Loader data.Loader
Expand Down Expand Up @@ -77,7 +78,7 @@ func Run(cfg Config) error {
return wrongUsage("specify only one of the following flags: -vschema, -vtexplain-vschema, -sharded")
}

if cfg.NumberOfShards > 0 && !(cfg.Sharded || cfg.VSchemaFile != "" || cfg.VtExplainVschemaFile != "") {
if cfg.NumberOfShards > 0 && !cfg.Sharded && cfg.VSchemaFile == "" && cfg.VtExplainVschemaFile == "" {
return wrongUsage("number-of-shards can only be used with -sharded, -vschema or -vtexplain-vschema")
}

Expand Down
2 changes: 1 addition & 1 deletion go/tester/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (t *Tracer) runQuery(q data.Query, ast sqlparser.Statement, state *state.St

reference := state.IsReferenceSet()
_, isSelect := ast.(sqlparser.SelectStatement)
if reference || !state.RunOnVitess() || !(isSelect || sqlparser.IsDMLStatement(ast)) {
if reference || !state.RunOnVitess() || (!isSelect && !sqlparser.IsDMLStatement(ast)) {
return nil
}

Expand Down