Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loading of dbUsername field for server config #2189

Merged
merged 1 commit into from
Jun 7, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Jun 3, 2022

In #1755 we changed from using mapstructure tags to using config tags, but I forgot to remove or update all the existing struct tags.

Every other field continued to work because the struct field name matched the convention. Unfortunately dbUsername was the one case where it did not match convention and required the struct tag. A workaround was to use dbUser or INFRA_SERVER_DB_USER.

This PR fixes the bug by renaming the field to DBUsername.

It also adds test coverage for every field in server.Options to show this is the only field with the problem.

I also removed the struct tags, since they no longer do anything and keeping them would be confusing. I'll leave some inline comments for where each of the fields is tested.

@dnephin dnephin force-pushed the dnephin/fix-server-config branch from 38fe290 to 6aa9317 Compare June 3, 2022 21:18
@@ -50,32 +51,6 @@ func TestServerCmd_LoadOptions(t *testing.T) {
}

testCases := []testCase{
{
name: "secret providers",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is now part of "all options from config" below.

Comment on lines -41 to -46
Server string `mapstructure:"server"`
Name string `mapstructure:"name"`
AccessKey string `mapstructure:"accessKey"`
CACert string `mapstructure:"caCert"`
CAKey string `mapstructure:"caKey"`
SkipTLSVerify bool `mapstructure:"skipTLSVerify"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is covered by an existing test: cmd.TestConnectorCmd

}

type KeyProvider struct {
Kind string `mapstructure:"kind" validate:"required"`
Kind string `validate:"required"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key provider and secret provider loading is covered by:

  • server.TestKeyProvider_PrepareForDecode_IntegrationWithDecode_FullConfig
  • server.TestSecretProvider_PrepareForDecode_IntegrationWithDecode_FullConfig

@@ -8,7 +8,7 @@ import (
)

type OptionsDiffV0dot1 struct {
Identities []User `mapstructure:"identities" validate:"dive"`
Identities []User `validate:"dive"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered by cmd.TestApplyVersion0ConfigToLatest

DBHost string
DBPort int
DBName string
DBUsername string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary fix is this one line

internal/cmd/server_test.go Outdated Show resolved Hide resolved
Add a test that covers all config fields.

Also remove mapstructure tags, which were not being used since we
changed to using cliopts for config loading.

Co-authored-by: Bruce MacDonald <[email protected]>
@dnephin dnephin force-pushed the dnephin/fix-server-config branch from 9396066 to b81a4ab Compare June 7, 2022 19:22
@dnephin dnephin merged commit 5cd7470 into main Jun 7, 2022
@dnephin dnephin deleted the dnephin/fix-server-config branch June 7, 2022 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants