diff --git a/go/vt/vtorc/logic/cell_discovery_test.go b/go/vt/vtorc/logic/cell_discovery_test.go new file mode 100644 index 00000000000..c52716ceff0 --- /dev/null +++ b/go/vt/vtorc/logic/cell_discovery_test.go @@ -0,0 +1,53 @@ +/* +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 logic + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + "vitess.io/vitess/go/vt/topo/memorytopo" + "vitess.io/vitess/go/vt/vtorc/db" + "vitess.io/vitess/go/vt/vtorc/inst" +) + +func TestRefreshAllCells(t *testing.T) { + // Store the old flags and restore on test completion + oldTs := ts + oldClustersToWatch := clustersToWatch + defer func() { + ts = oldTs + clustersToWatch = oldClustersToWatch + }() + + db.ClearVTOrcDatabase() + defer func() { + db.ClearVTOrcDatabase() + }() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ts = memorytopo.NewServer(ctx, "zone1", "zone2", "zone3") + + require.NoError(t, RefreshCells(ctx)) + + cells, err := inst.ReadCells() + require.NoError(t, err) + require.Equal(t, []string{"zone1", "zone2", "zone3"}, cells) +}