Skip to content

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented Oct 29, 2020

This PR consists of two main changes.

The first is a small cleanup of internal/config/config_type.go and internal/config/config_type_test.go to remove duplicate config option variables and also add testing around validating configuration keys.

The second is a slightly larger refactor of the config command. It extracts both the get and set command into separate files and changes their structure to match recently implemented commands, where the setup of the command is separated from the execution of the command, for increased testability. It also updates and adds test coverage for both of the commands.

There are no behavior changes in any of the config commands.

@samcoe samcoe self-assigned this Oct 29, 2020
@samcoe samcoe force-pushed the cleanup-duplicate-config branch 2 times, most recently from 01247a1 to e86b07e Compare October 29, 2020 12:01
@samcoe samcoe marked this pull request as ready for review October 29, 2020 12:08
return fmt.Errorf("invalid key")
}

func ValidateValue(key, value string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the exported Validate* functions to be used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are used in the config set command. Specifically in the setRun function.

}

func (c *fileConfig) Set(hostname, key, value string) error {
if err := validateConfigEntry(key, value); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This removes validation in Set and does not replace it with anything. Is this a regression?

Copy link
Contributor Author

@samcoe samcoe Oct 29, 2020

Choose a reason for hiding this comment

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

I did change the responsibility of the function here by removing the validation and putting it directly in the config set command. Specifically in the setRun function. This was the only caller of the Set function using user input, that needs validation, that I could find so it felt okay to move the responsibility of checking the validity of the value up to the config set command where the user input is actually coming in.

@vilmibm vilmibm self-requested a review November 2, 2020 17:42
@samcoe samcoe force-pushed the cleanup-duplicate-config branch from 77e4904 to 58b93e7 Compare November 3, 2020 06:49
@samcoe samcoe requested review from mislav and vilmibm November 3, 2020 06:49
@vilmibm vilmibm merged commit 441f40b into trunk Nov 3, 2020
@vilmibm vilmibm deleted the cleanup-duplicate-config branch November 3, 2020 18:54
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.

3 participants