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

Adds a new Ask to questioner for bools with a default value. Also adds tests. #6449

Conversation

beqqrry-aws
Copy link
Contributor

No description provided.

@beqqrry-aws beqqrry-aws added Go-v2 This issue relates to the AWS SDK for Go V2 Task A general update to the code base for language clarification, missing actions, tests, etc. labels May 10, 2024
@beqqrry-aws beqqrry-aws self-assigned this May 10, 2024
Comment on lines 144 to 147
func (questioner Questioner) AskBoolWithDefault(question string, expected string, defaultValue string) bool {
answer := questioner.Ask(question)
return strings.ToLower(answer) == expected || strings.ToLower(expected) == strings.ToLower(defaultValue)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This works fine, but I almost would prefer defaultResponse bool instead of defaultValue and then

return strings.ToLower(answer) == expected || defaultResponse

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 made me realize I was missing some test coverage for when the default response is affirmative but the provided response by the user is negative. I'll rewrite and then take a look at using a bool instead of a string.

@beqqrry-aws beqqrry-aws force-pushed the go_demotools_add_ask_book_default branch from fb1289e to 4729243 Compare May 10, 2024 22:28
Comment on lines +61 to +99
func TestQuestioner_AskBoolWithDefault_yY_Blank(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "y", "Y", "", true)
}

func TestQuestioner_AskBoolWithDefault_yN_Blank(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "y", "N", "", false)
}
func TestQuestioner_AskBoolWithDefault_nY_Blank(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "n", "Y", "", false)
}
func TestQuestioner_AskBoolWithDefault_nN_Blank(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "n", "N", "", true)
}

func TestQuestioner_AskBoolWithDefault_yY_y(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "y", "Y", "y", true)
}
func TestQuestioner_AskBoolWithDefault_yN_y(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "y", "N", "y", true)
}
func TestQuestioner_AskBoolWithDefault_nY_y(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "n", "Y", "y", false)
}
func TestQuestioner_AskBoolWithDefault_nN_y(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "n", "N", "y", false)
}

func TestQuestioner_AskBoolWithDefault_yY_n(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "y", "Y", "n", false)
}
func TestQuestioner_AskBoolWithDefault_yN_n(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "y", "N", "n", false)
}
func TestQuestioner_AskBoolWithDefault_nY_n(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "n", "Y", "n", true)
}
func TestQuestioner_AskBoolWithDefault_nN_n(t *testing.T) {
AskBoolWithDefault_ByArguments(t, "n", "N", "n", true)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a lot of these are redundant, because y or n doesn't matter, it's more like a or b, and aA or bB are equivalent, so your set of cases should be:

aA""
aB""
aAa
aAb
aBa
aBb

It might not be fewer lines, but I might have made a struct and then a list of objects, like:

type testArgs struct {
    expected string
    defaultVal string
    entry string
    result bool
}

tests := []testArgs{
   {"a", "A", "", true},
   ... etc ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go-v2 This issue relates to the AWS SDK for Go V2 Task A general update to the code base for language clarification, missing actions, tests, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants