Refactor into subtests

This commit is contained in:
kencx
2022-05-28 16:14:29 +08:00
parent 1dda710d48
commit 706278a215

View File

@@ -7,25 +7,28 @@ import (
"testing"
)
func TestOptionToStringWithoutPrefix(t *testing.T) {
func TestOptionToString(t *testing.T) {
t.Run("no prefix", func(t *testing.T) {
opt := "test"
result := optionToString(opt)
assertEqual(t, result, "--test")
}
})
func TestOptionsToStringWithSinglePrefix(t *testing.T) {
t.Run("single prefix", func(t *testing.T) {
opt := "-test"
result := optionToString(opt)
assertEqual(t, result, "-test")
}
})
func TestOptionsToStringWithDoublePrefix(t *testing.T) {
t.Run("double prefix", func(t *testing.T) {
opt := "--test"
result := optionToString(opt)
assertEqual(t, result, "--test")
})
}
func TestAppendOneOptionToSlice(t *testing.T) {
t.Run("string flag", func(t *testing.T) {
result := []string{}
optionMap := OptionMap{"string-flag": []interface{}{"/root"}}
@@ -34,9 +37,9 @@ func TestAppendOneOptionToSlice(t *testing.T) {
"--string-flag", "/root",
}
assertSliceEqual(t, result, expected)
}
})
func TestAppendBoolOptionToSlice(t *testing.T) {
t.Run("bool flag", func(t *testing.T) {
result := []string{}
optionMap := OptionMap{"boolean-flag": []interface{}{true}}
@@ -45,6 +48,18 @@ func TestAppendBoolOptionToSlice(t *testing.T) {
"--boolean-flag",
}
assertSliceEqual(t, result, expected)
})
t.Run("int flag", func(t *testing.T) {
result := []string{}
optionMap := OptionMap{"int-flag": []interface{}{123}}
appendOptionsToSlice(&result, optionMap)
expected := []string{
"--int-flag", "123",
}
assertSliceEqual(t, result, expected)
})
}
func TestAppendMultipleOptionsToSlice(t *testing.T) {