Skip to content

Commit 649b0cf

Browse files
ncodeclaude
andcommitted
refactor: clean up viper usage in integration tests
- Use setupViper consistently for both ballots in LeaderFailover test - Add clarifying comments explaining that Ballot copies config at creation time, so viper resets don't affect already-created instances 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent b641145 commit 649b0cf

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

internal/ballot/ballot_integration_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,15 @@ func TestIntegration_LeaderFailover(t *testing.T) {
158158
defer cancel()
159159

160160
// Setup and create first ballot
161+
// Note: Ballot copies config at creation time, so resetting viper after
162+
// ballot1 is created won't affect it.
161163
setupViper(t, serviceID1, electionKey)
162164
ballot1, err := New(ctx, serviceID1)
163165
require.NoError(t, err)
164166
defer ballot1.releaseSession()
165167

166-
// Setup and create second ballot
167-
viper.Set(fmt.Sprintf("election.services.%s.id", serviceID2), serviceID2)
168-
viper.Set(fmt.Sprintf("election.services.%s.key", serviceID2), electionKey)
169-
viper.Set(fmt.Sprintf("election.services.%s.primaryTag", serviceID2), testPrimaryTag)
170-
viper.Set(fmt.Sprintf("election.services.%s.serviceChecks", serviceID2), []string{fmt.Sprintf("service:%s", serviceID2)})
171-
viper.Set(fmt.Sprintf("election.services.%s.ttl", serviceID2), "10s")
172-
viper.Set(fmt.Sprintf("election.services.%s.lockDelay", serviceID2), "1s")
168+
// Setup and create second ballot with fresh viper config
169+
setupViper(t, serviceID2, electionKey)
173170
ballot2, err := New(ctx, serviceID2)
174171
require.NoError(t, err)
175172
defer ballot2.releaseSession()
@@ -310,6 +307,8 @@ func TestIntegration_MultipleInstances(t *testing.T) {
310307
defer cancel()
311308

312309
// Register multiple services and create ballots
310+
// Note: Each iteration resets viper, but Ballot copies config at creation
311+
// time, so previously created ballots are unaffected.
313312
for i := 0; i < numInstances; i++ {
314313
services[i] = fmt.Sprintf("%s-%d", baseID, i)
315314
registerTestService(t, client, services[i], 8090+i)

0 commit comments

Comments
 (0)