docker-gen/internal/utils/utils_test.go
guoguangwu 77efaca970 chore: remove refs to deprecated io/ioutil
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-07-10 10:46:33 +08:00

45 lines
788 B
Go

package utils
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSplitKeyValueSlice(t *testing.T) {
tests := []struct {
input []string
expected string
}{
{[]string{"K"}, ""},
{[]string{"K="}, ""},
{[]string{"K=V3"}, "V3"},
{[]string{"K=V4=V5"}, "V4=V5"},
}
for _, i := range tests {
v := SplitKeyValueSlice(i.input)
if v["K"] != i.expected {
t.Fatalf("expected K='%s'. got '%s'", i.expected, v["K"])
}
}
}
func TestPathExists(t *testing.T) {
file, err := os.CreateTemp("", "test")
if err != nil {
t.Fatal(err)
}
defer os.Remove(file.Name())
exists, err := PathExists(file.Name())
assert.NoError(t, err)
assert.True(t, exists)
exists, err = PathExists("/wrong/path")
assert.NoError(t, err)
assert.False(t, exists)
}