Skip to content

Commit 46f70c1

Browse files
committed
Config: Improve caching tests in config_cluster.go
Signed-off-by: Michael Mayer <[email protected]>
1 parent 3624e73 commit 46f70c1

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

internal/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ func NewConfig(ctx *cli.Context) *Config {
172172
if optionsYaml := c.OptionsYaml(); fs.FileExists(optionsYaml) {
173173
if err := c.options.Load(optionsYaml); err != nil {
174174
log.Warnf("config: failed loading values from %s (%s)", clean.Log(optionsYaml), err)
175+
} else if c.env == EnvDevelop {
176+
// Reduce the log level to minimize noise in the test logs.
177+
log.Tracef("config: overriding config with values from %s", clean.Log(optionsYaml))
175178
} else {
176179
log.Debugf("config: overriding config with values from %s", clean.Log(optionsYaml))
177180
}

internal/config/config_cluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,15 @@ func (c *Config) SaveJoinToken(customToken string) (token string, fileName strin
203203
return "", "", fmt.Errorf("could not write cluster join token (%w)", err)
204204
}
205205

206+
// Use an in-memory cache with a
207+
// short TTL to cache the token.
206208
if c.cache != nil {
207209
c.cache.SetDefault(fileName, token)
210+
c.options.JoinToken = ""
211+
} else {
212+
// Store token in Options
213+
// if cache is unavailable.
214+
c.options.JoinToken = token
208215
}
209216

210217
return token, fileName, nil

internal/config/config_cluster_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,11 @@ func TestConfig_Cluster(t *testing.T) {
289289
c := NewConfig(ctx)
290290
c.options.NodeRole = cluster.RolePortal
291291

292+
c.options.JoinToken = "onwnOVt-MZCCkA0z-YJXHnzJ"
292293
token, tokenFile, err := c.SaveJoinToken("")
293294
assert.NoError(t, err)
295+
assert.Empty(t, c.options.JoinToken)
296+
assert.Equal(t, token, c.JoinToken())
294297
assert.True(t, rnd.IsJoinToken(token, false))
295298
assert.FileExists(t, tokenFile)
296299

0 commit comments

Comments
 (0)