mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2026-04-02 20:05:23 +00:00
Refactor into subtests
This commit is contained in:
@@ -7,44 +7,59 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOptionToStringWithoutPrefix(t *testing.T) {
|
func TestOptionToString(t *testing.T) {
|
||||||
opt := "test"
|
t.Run("no prefix", func(t *testing.T) {
|
||||||
result := optionToString(opt)
|
opt := "test"
|
||||||
assertEqual(t, result, "--test")
|
result := optionToString(opt)
|
||||||
}
|
assertEqual(t, result, "--test")
|
||||||
|
})
|
||||||
|
|
||||||
func TestOptionsToStringWithSinglePrefix(t *testing.T) {
|
t.Run("single prefix", func(t *testing.T) {
|
||||||
opt := "-test"
|
opt := "-test"
|
||||||
result := optionToString(opt)
|
result := optionToString(opt)
|
||||||
assertEqual(t, result, "-test")
|
assertEqual(t, result, "-test")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestOptionsToStringWithDoublePrefix(t *testing.T) {
|
t.Run("double prefix", func(t *testing.T) {
|
||||||
opt := "--test"
|
opt := "--test"
|
||||||
result := optionToString(opt)
|
result := optionToString(opt)
|
||||||
assertEqual(t, result, "--test")
|
assertEqual(t, result, "--test")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppendOneOptionToSlice(t *testing.T) {
|
func TestAppendOneOptionToSlice(t *testing.T) {
|
||||||
result := []string{}
|
t.Run("string flag", func(t *testing.T) {
|
||||||
optionMap := OptionMap{"string-flag": []interface{}{"/root"}}
|
result := []string{}
|
||||||
|
optionMap := OptionMap{"string-flag": []interface{}{"/root"}}
|
||||||
|
|
||||||
appendOptionsToSlice(&result, optionMap)
|
appendOptionsToSlice(&result, optionMap)
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"--string-flag", "/root",
|
"--string-flag", "/root",
|
||||||
}
|
}
|
||||||
assertSliceEqual(t, result, expected)
|
assertSliceEqual(t, result, expected)
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestAppendBoolOptionToSlice(t *testing.T) {
|
t.Run("bool flag", func(t *testing.T) {
|
||||||
result := []string{}
|
result := []string{}
|
||||||
optionMap := OptionMap{"boolean-flag": []interface{}{true}}
|
optionMap := OptionMap{"boolean-flag": []interface{}{true}}
|
||||||
|
|
||||||
appendOptionsToSlice(&result, optionMap)
|
appendOptionsToSlice(&result, optionMap)
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"--boolean-flag",
|
"--boolean-flag",
|
||||||
}
|
}
|
||||||
assertSliceEqual(t, result, expected)
|
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) {
|
func TestAppendMultipleOptionsToSlice(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user