config test fix

This commit is contained in:
Nikola Jokic 2025-06-05 13:44:55 +02:00
parent da0ca64125
commit e8c330d351
No known key found for this signature in database
GPG Key ID: E4104494F9B8DDF6
2 changed files with 11 additions and 6 deletions

View File

@ -112,8 +112,13 @@ func (c *Config) Validate() error {
return fmt.Errorf(`MinRunners "%d" cannot be greater than MaxRunners "%d"`, c.MinRunners, c.MaxRunners)
}
if c.VaultType != "" && c.VaultLookupKey == "" {
return fmt.Errorf("VaultLookupKey is required when VaultType is set to %q", c.VaultType)
if c.VaultType != "" {
if err := c.VaultType.Validate(); err != nil {
return fmt.Errorf("VaultType validation failed: %w", err)
}
if c.VaultLookupKey == "" {
return fmt.Errorf("VaultLookupKey is required when VaultType is set to %q", c.VaultType)
}
}
if c.VaultType == "" && c.VaultLookupKey == "" {

View File

@ -53,7 +53,7 @@ func TestConfigValidationAppKey(t *testing.T) {
RunnerScaleSetId: 1,
}
err := config.Validate()
expectedError := fmt.Sprintf(`GitHub auth credential is missing, token length: "%d", appId: %q, installationId: "%d", private key length: "%d"`, len(config.Token), config.AppID, config.AppInstallationID, len(config.AppPrivateKey))
expectedError := "AppConfig validation failed: no credentials provided: either a PAT or GitHub App credentials should be provided"
assert.ErrorContains(t, err, expectedError, "Expected error about missing auth")
})
@ -70,7 +70,7 @@ func TestConfigValidationAppKey(t *testing.T) {
RunnerScaleSetId: 1,
}
err := config.Validate()
expectedError := fmt.Sprintf(`GitHub auth credential is missing, token length: "%d", appId: %q, installationId: "%d", private key length: "%d"`, len(config.Token), config.AppID, config.AppInstallationID, len(config.AppPrivateKey))
expectedError := "AppConfig validation failed: no credentials provided: either a PAT or GitHub App credentials should be provide"
assert.ErrorContains(t, err, expectedError, "Expected error about missing auth")
})
}
@ -89,7 +89,7 @@ func TestConfigValidationOnlyOneTypeOfCredentials(t *testing.T) {
RunnerScaleSetId: 1,
}
err := config.Validate()
expectedError := fmt.Sprintf(`only one GitHub auth method supported at a time. Have both PAT and App auth: token length: "%d", appId: %q, installationId: "%d", private key length: "%d"`, len(config.Token), config.AppID, config.AppInstallationID, len(config.AppPrivateKey))
expectedError := fmt.Sprintf(`AppConfig validation failed: both PAT and GitHub App credentials provided. should only provide one`)
assert.ErrorContains(t, err, expectedError, "Expected error about missing auth")
}
@ -166,6 +166,6 @@ func TestConfigValidationWithVaultConfig(t *testing.T) {
VaultLookupKey: "",
}
err := config.Validate()
assert.ErrorContains(t, err, `vault type set to "invalid_vault_type", but lookup key is empty`, "Expected error for vault type without lookup key")
assert.ErrorContains(t, err, `VaultLookupKey is required when VaultType is set to "azure_key_vault"`, "Expected error for vault type without lookup key")
})
}