Skip to content

Commit

Permalink
test: full coverage for internal/state
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Nov 19, 2022
1 parent f489edf commit 6c0a5bf
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
6 changes: 6 additions & 0 deletions internal/mirrors/mirrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func GetMirrorURLByAliases(osType int, alias string) string {
return mirror.URL
}
}
case Define.TYPE_LINUX_DISTROS_ALPINE:
for _, mirror := range Define.BUILDIN_ALPINE_MIRRORS {
if mirror.Alias == alias {
return mirror.URL
}
}
}
return ""
}
Expand Down
8 changes: 4 additions & 4 deletions internal/state/alpine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var ALPINE_MIRROR *url.URL

func SetAlpineMirror(input string) {
if input == "" {
CENTOS_MIRROR = nil
ALPINE_MIRROR = nil
return
}

Expand All @@ -26,13 +26,13 @@ func SetAlpineMirror(input string) {
ALPINE_MIRROR = nil
return
}
CENTOS_MIRROR = url
ALPINE_MIRROR = url
}

func GetAlpineMirror() *url.URL {
return CENTOS_MIRROR
return ALPINE_MIRROR
}

func ResetAlpineMirror() {
CENTOS_MIRROR = nil
ALPINE_MIRROR = nil
}
12 changes: 12 additions & 0 deletions internal/state/alpine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ func TestGetAndSetAlpineMirror(t *testing.T) {
if mirror != nil {
t.Fatal("Test Clear Alpine Mirror Faild")
}

State.SetAlpineMirror("cn:tsinghua")
mirror = State.GetAlpineMirror()
if !strings.Contains(strings.ToLower(mirror.Path), "alpine") {
t.Fatal("Test Set/Get Alpine Mirror Value Faild")
}

State.SetAlpineMirror("!#$%(not://abc")
mirror = State.GetAlpineMirror()
if mirror != nil {
t.Fatal("Test Set/Get Alpine Mirror Value Faild")
}
}
12 changes: 12 additions & 0 deletions internal/state/centos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ func TestGetAndSetCentOSMirror(t *testing.T) {
if mirror != nil {
t.Fatal("Test Clear CentOS Mirror Faild")
}

State.SetCentOSMirror("cn:tsinghua")
mirror = State.GetCentOSMirror()
if !strings.Contains(strings.ToLower(mirror.Path), "centos") {
t.Fatal("Test Set/Get CentOS Mirror Value Faild")
}

State.SetCentOSMirror("!#$%(not://abc")
mirror = State.GetCentOSMirror()
if mirror != nil {
t.Fatal("Test Set/Get CentOS Mirror Value Faild")
}
}
12 changes: 12 additions & 0 deletions internal/state/debian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ func TestGetAndSetDebianMirror(t *testing.T) {
if mirror != nil {
t.Fatal("Test Clear Debian Mirror Faild")
}

State.SetDebianMirror("cn:tsinghua")
mirror = State.GetDebianMirror()
if !strings.Contains(strings.ToLower(mirror.Path), "debian") {
t.Fatal("Test Set/Get Debian Mirror Value Faild")
}

State.SetDebianMirror("!#$%(not://abc")
mirror = State.GetDebianMirror()
if mirror != nil {
t.Fatal("Test Set/Get Debian Mirror Value Faild")
}
}
12 changes: 12 additions & 0 deletions internal/state/ubuntu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ func TestGetAndSetUbuntuMirror(t *testing.T) {
if mirror != nil {
t.Fatal("Test Clear Ubuntu Mirror Faild")
}

State.SetUbuntuMirror("cn:tsinghua")
mirror = State.GetUbuntuMirror()
if !strings.Contains(strings.ToLower(mirror.Path), "ubuntu") {
t.Fatal("Test Set/Get Ubuntu Mirror Value Faild")
}

State.SetUbuntuMirror("!#$%(not://abc")
mirror = State.GetUbuntuMirror()
if mirror != nil {
t.Fatal("Test Set/Get Ubuntu Mirror Value Faild")
}
}

0 comments on commit 6c0a5bf

Please sign in to comment.