Skip to content

Commit

Permalink
chore: improve coverage, fix mirror set func
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Jun 13, 2022
1 parent 67fcb55 commit 72c5ecd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ go run apt-proxy.go
# go test -cover ./...

? github.com/soulteary/apt-proxy [no test files]
ok github.com/soulteary/apt-proxy/cli 0.852s coverage: 73.9% of statements
ok github.com/soulteary/apt-proxy/linux 7.465s coverage: 82.7% of statements
ok github.com/soulteary/apt-proxy/pkgs/httpcache (cached) coverage: 82.7% of statements
ok github.com/soulteary/apt-proxy/cli 3.889s coverage: 73.9% of statements
ok github.com/soulteary/apt-proxy/linux 9.660s coverage: 80.0% of statements
ok github.com/soulteary/apt-proxy/pkgs/httpcache 1.943s coverage: 82.7% of statements
? github.com/soulteary/apt-proxy/pkgs/httplog [no test files]
ok github.com/soulteary/apt-proxy/pkgs/stream.v1 (cached) coverage: 100.0% of statements
ok github.com/soulteary/apt-proxy/pkgs/vfs (cached) coverage: 59.3% of statements
ok github.com/soulteary/apt-proxy/pkgs/stream.v1 0.934s coverage: 100.0% of statements
ok github.com/soulteary/apt-proxy/pkgs/vfs 1.069s coverage: 59.3% of statements
? github.com/soulteary/apt-proxy/proxy [no test files]
? github.com/soulteary/apt-proxy/state [no test files]
ok github.com/soulteary/apt-proxy/state 1.555s coverage: 100.0% of statements
```
View coverage report:
Expand Down
2 changes: 1 addition & 1 deletion linux/rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestCreateNewRewritersWithSpecifyMirror(t *testing.T) {
t.Fatal("mirror path incorrect")
}

state.ClearUbuntuMirror()
state.ResetUbuntuMirror()
}

func TestMatchingRule(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func SetUbuntuMirror(mirror string) {
url, err := url.Parse(mirror)
if err != nil || mirror == "" {
UBUNTU_MIRROR = nil
return
}
UBUNTU_MIRROR = url
}
Expand All @@ -28,14 +29,15 @@ func GetUbuntuMirror() *url.URL {
return UBUNTU_MIRROR
}

func ClearUbuntuMirror() {
func ResetUbuntuMirror() {
UBUNTU_MIRROR = nil
}

func SetDebianMirror(mirror string) {
url, err := url.Parse(mirror)
if err != nil || mirror == "" {
DEBIAN_MIRROR = nil
return
}
DEBIAN_MIRROR = url
}
Expand All @@ -44,6 +46,6 @@ func GetDebianMirror() *url.URL {
return DEBIAN_MIRROR
}

func ClearDebianMirror() {
func ResetDebianMirror() {
DEBIAN_MIRROR = nil
}
54 changes: 54 additions & 0 deletions state/state_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package state

import (
"strings"
"testing"
)

func TestSetProxyMode(t *testing.T) {
// 1 => linux.TYPE_LINUX_DISTROS_UBUNTU
SetProxyMode(1)
if GetProxyMode() != 1 {
t.Fatal("Test Set/Get ProxyMode Faild")
}
}

func TestGetAndSetUbuntuMirror(t *testing.T) {
SetUbuntuMirror("https://mirrors.tuna.tsinghua.edu.cn/ubuntu/")
mirror := GetUbuntuMirror()
if !strings.Contains(mirror.Path, "ubuntu") {
t.Fatal("Test Set/Get Ubuntu Mirror Value Faild")
}

SetUbuntuMirror("")
mirror = GetUbuntuMirror()
if mirror != nil {
t.Fatal("Test Set/Get Ubuntu Mirror to Null Faild")
}

ResetUbuntuMirror()
mirror = GetUbuntuMirror()
if mirror != nil {
t.Fatal("Test Clear Ubuntu Mirror Faild")
}
}

func TestGetAndSetDebianMirror(t *testing.T) {
SetDebianMirror("https://mirrors.tuna.tsinghua.edu.cn/debian/")
mirror := GetDebianMirror()
if !strings.Contains(mirror.Path, "debian") {
t.Fatal("Test Set/Get Debian Mirror Value Faild")
}

SetDebianMirror("")
mirror = GetDebianMirror()
if mirror != nil {
t.Fatal("Test Set/Get Debian Mirror to Null Faild")
}

ResetDebianMirror()
mirror = GetDebianMirror()
if mirror != nil {
t.Fatal("Test Clear Debian Mirror Faild")
}
}

0 comments on commit 72c5ecd

Please sign in to comment.