add unittest for storage (#894)

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2023-06-13 12:20:40 +08:00 committed by GitHub
parent d3c34d61f2
commit 2f0bc4b2e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 0 deletions

View File

@ -140,3 +140,65 @@ func TestStorage_resolveFile(t *testing.T) {
})
}
}
func TestNormalizePath(t *testing.T) {
tests := []struct {
name string
base string
path string
want string
}{
{
name: "unix path relative path",
base: "/root",
path: "local/timespan-application.yml",
want: "/local/timespan-application.yml",
},
{
name: "unix path absolute path",
base: "/data",
path: "/root/data/timespan-application.yml",
want: "/root/data/timespan-application.yml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
storageIns := NewStorage(tt.base, helmexec.NewLogger(io.Discard, "debug"), filesystem.DefaultFileSystem())
if got := storageIns.normalizePath(tt.path); got != tt.want {
t.Errorf("normalizePath() = %v, want %v", got, tt.want)
}
})
}
}
func TestJoinBase(t *testing.T) {
tests := []struct {
name string
base string
path string
want string
}{
{
name: "joinBase with non-root base",
base: "/root",
path: "local/timespan-application.yml",
want: "/local/timespan-application.yml",
},
{
name: "joinBase with root path",
base: "/",
path: "data/timespan-application.yml",
want: "/data/timespan-application.yml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
storageIns := NewStorage(tt.base, helmexec.NewLogger(io.Discard, "debug"), filesystem.DefaultFileSystem())
if got := storageIns.JoinBase(tt.path); got != tt.want {
t.Errorf("JoinBase() = %v, want %v", got, tt.want)
}
})
}
}