Skip to content

Commit 843d46c

Browse files
committed
Add tests for findBaseDir
1 parent 89715b0 commit 843d46c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tools/download.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ func stringInSlice(str string, list []string) bool {
319319
}
320320

321321
func findBaseDir(dirList []string) string {
322+
if len(dirList) == 1 {
323+
return filepath.Dir(dirList[0]) + "/"
324+
}
322325
baseDir := ""
323326
// https://github.com/backdrop-ops/contrib/issues/55#issuecomment-73814500
324327
dontdiff := []string{"pax_global_header"}

tools/download_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package tools
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func Test_findBaseDir(t *testing.T) {
9+
cases := []struct {
10+
dirList []string
11+
want string
12+
}{
13+
{[]string{"bin/bossac"}, "bin/"},
14+
{[]string{"bin/", "bin/bossac"}, "bin/"},
15+
{[]string{"bin/", "bin/bossac", "example"}, ""},
16+
}
17+
for _, tt := range cases {
18+
t.Run(fmt.Sprintln(tt.dirList), func(t *testing.T) {
19+
if got := findBaseDir(tt.dirList); got != tt.want {
20+
t.Errorf("findBaseDir() = %v, want %v", got, tt.want)
21+
}
22+
})
23+
}
24+
}

0 commit comments

Comments
 (0)