Files
docker-registry-ui/registry/common_test.go
Roman Vynar 67d82c7d59 Amend tag info page, change logging.
* Amend representation of the tag info page
* Change logging library, add "-log-level" argument and put most of the logging into DEBUG mode
2020-02-18 23:31:56 +02:00

58 lines
1.5 KiB
Go

package registry
import (
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestSortedMapKeys(t *testing.T) {
a := map[string]string{
"foo": "bar",
"abc": "bar",
"zoo": "bar",
}
b := map[string]timeSlice{
"zoo": []tagData{tagData{name: "1", created: time.Now()}},
"abc": []tagData{tagData{name: "1", created: time.Now()}},
"foo": []tagData{tagData{name: "1", created: time.Now()}},
}
c := map[string][]string{
"zoo": []string{"1", "2"},
"foo": []string{"1", "2"},
"abc": []string{"1", "2"},
}
expect := []string{"abc", "foo", "zoo"}
convey.Convey("Sort map keys", t, func() {
convey.So(SortedMapKeys(a), convey.ShouldResemble, expect)
convey.So(SortedMapKeys(b), convey.ShouldResemble, expect)
convey.So(SortedMapKeys(c), convey.ShouldResemble, expect)
})
}
func TestPrettySize(t *testing.T) {
convey.Convey("Format bytes", t, func() {
input := map[float64]string{
123: "123 B",
23123: "23 KB",
23923: "23 KB",
723425120: "689.9 MB",
8534241213: "7.95 GB",
}
for key, val := range input {
convey.So(PrettySize(key), convey.ShouldEqual, val)
}
})
}
func TestItemInSlice(t *testing.T) {
a := []string{"abc", "def", "ghi"}
convey.Convey("Check whether element is in slice", t, func() {
convey.So(ItemInSlice("abc", a), convey.ShouldBeTrue)
convey.So(ItemInSlice("ghi", a), convey.ShouldBeTrue)
convey.So(ItemInSlice("abc1", a), convey.ShouldBeFalse)
convey.So(ItemInSlice("gh", a), convey.ShouldBeFalse)
})
}