Skip to content

Commit 6ff26a9

Browse files
committed
Added more tests
1 parent d899df4 commit 6ff26a9

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

pkg/api/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ package api
77
import (
88
"encoding/json"
99
"fmt"
10-
"github.com/scaleway/scaleway-cli/pkg/utils"
1110
"os"
11+
12+
"github.com/scaleway/scaleway-cli/pkg/utils"
1213
)
1314

1415
// Config is a Scaleway CLI configuration file

pkg/utils/utils_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package utils
22

33
import (
4+
"sort"
5+
"strings"
46
"testing"
57

68
. "github.com/smartystreets/goconvey/convey"
@@ -42,3 +44,43 @@ func TestPathToTARPathparts(t *testing.T) {
4244
So([]string{"/long/path/to", "dir"}, ShouldResemble, []string{dir, base})
4345
})
4446
}
47+
48+
func TestRemoveDuplicates(t *testing.T) {
49+
Convey("Testing RemoveDuplicates()", t, func() {
50+
slice := RemoveDuplicates([]string{"a", "b", "c", "a"})
51+
sort.Strings(slice)
52+
So(slice, ShouldResemble, []string{"a", "b", "c"})
53+
54+
slice = RemoveDuplicates([]string{"a", "b", "c", "a"})
55+
sort.Strings(slice)
56+
So(slice, ShouldResemble, []string{"a", "b", "c"})
57+
58+
slice = RemoveDuplicates([]string{"a", "b", "c", "a", "a", "b", "d"})
59+
sort.Strings(slice)
60+
So(slice, ShouldResemble, []string{"a", "b", "c", "d"})
61+
62+
slice = RemoveDuplicates([]string{"a", "b", "c", "a", ""})
63+
sort.Strings(slice)
64+
So(slice, ShouldResemble, []string{"", "a", "b", "c"})
65+
})
66+
}
67+
68+
func TestGetHomeDir(t *testing.T) {
69+
Convey("Testing GetHomeDir()", t, func() {
70+
homedir, err := GetHomeDir()
71+
So(err, ShouldBeNil)
72+
So(homedir, ShouldNotEqual, "")
73+
})
74+
}
75+
76+
func TestGetConfigFilePath(t *testing.T) {
77+
Convey("Testing GetConfigFilePath()", t, func() {
78+
configPath, err := GetConfigFilePath()
79+
So(err, ShouldBeNil)
80+
So(configPath, ShouldNotEqual, "")
81+
82+
homedir, err := GetHomeDir()
83+
So(err, ShouldBeNil)
84+
So(strings.Contains(configPath, homedir), ShouldBeTrue)
85+
})
86+
}

0 commit comments

Comments
 (0)