Seed defaultComponents in bootstrap signing tests
`resetCmdArgs` in `main_test.go` rebuilds `bootstrapArgs` from `NewBootstrapFlags`, which deliberately omits the cobra-populated `defaultComponents`. In the `e2e` build, `TestMain` runs `flux install …` before any test executes; that call triggers the reset and leaves `bootstrapArgs.defaultComponents` empty for the lifetime of the process. `bootstrapValidate` then trips on its `requiredComponents` pre-check and fails with "component source-controller is required" before it ever reaches the SSH/GPG signing flag validation that this test cares about. Save, seed, and restore `defaultComponents` per subtest so the required-component check passes regardless of whether the test runs under the plain or the `e2e` build tag. Assisted-by: claude/opus-4.7 Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This commit is contained in:
@@ -112,6 +112,7 @@ func TestBootstrapValidate_signingFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
savedDefaultComponents := bootstrapArgs.defaultComponents
|
||||||
savedGpgRing := bootstrapArgs.gpgKeyRingPath
|
savedGpgRing := bootstrapArgs.gpgKeyRingPath
|
||||||
savedGpgPass := bootstrapArgs.gpgPassphrase
|
savedGpgPass := bootstrapArgs.gpgPassphrase
|
||||||
savedSshKey := bootstrapArgs.sshSigningKeyFile
|
savedSshKey := bootstrapArgs.sshSigningKeyFile
|
||||||
@@ -120,6 +121,7 @@ func TestBootstrapValidate_signingFlags(t *testing.T) {
|
|||||||
savedPrivKey := bootstrapArgs.privateKeyFile
|
savedPrivKey := bootstrapArgs.privateKeyFile
|
||||||
savedReuse := bootstrapArgs.sshSigningReusePrivateKey
|
savedReuse := bootstrapArgs.sshSigningReusePrivateKey
|
||||||
defer func() {
|
defer func() {
|
||||||
|
bootstrapArgs.defaultComponents = savedDefaultComponents
|
||||||
bootstrapArgs.gpgKeyRingPath = savedGpgRing
|
bootstrapArgs.gpgKeyRingPath = savedGpgRing
|
||||||
bootstrapArgs.gpgPassphrase = savedGpgPass
|
bootstrapArgs.gpgPassphrase = savedGpgPass
|
||||||
bootstrapArgs.sshSigningKeyFile = savedSshKey
|
bootstrapArgs.sshSigningKeyFile = savedSshKey
|
||||||
@@ -129,6 +131,10 @@ func TestBootstrapValidate_signingFlags(t *testing.T) {
|
|||||||
bootstrapArgs.sshSigningReusePrivateKey = savedReuse
|
bootstrapArgs.sshSigningReusePrivateKey = savedReuse
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// The e2e TestMain calls resetCmdArgs which clears the
|
||||||
|
// cobra-populated default components, so seed them here to
|
||||||
|
// satisfy the requiredComponents pre-check in bootstrapValidate.
|
||||||
|
bootstrapArgs.defaultComponents = bootstrapArgs.requiredComponents
|
||||||
bootstrapArgs.gpgKeyRingPath = tt.gpgRing
|
bootstrapArgs.gpgKeyRingPath = tt.gpgRing
|
||||||
bootstrapArgs.gpgPassphrase = tt.gpgPass
|
bootstrapArgs.gpgPassphrase = tt.gpgPass
|
||||||
bootstrapArgs.sshSigningKeyFile = tt.sshKey
|
bootstrapArgs.sshSigningKeyFile = tt.sshKey
|
||||||
|
|||||||
Reference in New Issue
Block a user