Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Oct 30, 2024
1 parent c683fbe commit 651c490
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions go/cmd/vttablet/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2024 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 cli

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
)

// TestRunFailsToStartTabletManager tests the code path in 'run' where we fail to start the TabletManager
// this is done by starting vttablet without a cnf file but requesting it to restore from backup.
// When starting, the TabletManager checks if it needs to restore, in tm.handleRestore but this step will
// fail if we do not provide a cnf file and if the flag --restore_from_backup is provided.
func TestRunFailsToStartTabletManager(t *testing.T) {
tabletPath = "cell-1"
ts, factory := memorytopo.NewServerAndFactory(context.Background(), "cell")
topo.RegisterFactory("test", factory)

args := append([]string{}, os.Args...)
t.Cleanup(func() {
ts.Close()
tabletPath = ""
os.Args = append([]string{}, args...)
})

os.Args = []string{"vttablet",
"--topo_implementation", "test", "--topo_global_server_address", "localhost", "--topo_global_root", "cell",
"--db_host", "localhost", "--db_port", "3306",
"--tablet-path", "cell-1", "--init_keyspace", "ks", "--init_shard", "0", "--init_tablet_type", "replica",
"--restore_from_backup",
}

err := Main.Execute()
require.ErrorContains(t, err, "you cannot enable --restore_from_backup without a my.cnf file")
}

0 comments on commit 651c490

Please sign in to comment.