Skip to content

Commit

Permalink
chore: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Jun 15, 2022
1 parent 03b8059 commit 923bcd2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ go run apt-proxy.go
# go test -cover ./...

? github.com/soulteary/apt-proxy [no test files]
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
ok github.com/soulteary/apt-proxy/cli 2.477s coverage: 73.9% of statements
ok github.com/soulteary/apt-proxy/linux 7.329s coverage: 80.0% of statements
ok github.com/soulteary/apt-proxy/pkgs/httpcache 1.062s coverage: 82.7% of statements
? github.com/soulteary/apt-proxy/pkgs/httplog [no test files]
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]
ok github.com/soulteary/apt-proxy/state 1.555s coverage: 100.0% of statements
ok github.com/soulteary/apt-proxy/pkgs/stream.v1 0.551s coverage: 100.0% of statements
? github.com/soulteary/apt-proxy/pkgs/system [no test files]
ok github.com/soulteary/apt-proxy/pkgs/vfs 0.719s coverage: 59.3% of statements
? github.com/soulteary/apt-proxy/server [no test files]
ok github.com/soulteary/apt-proxy/state 0.617s coverage: 84.2% of statements
```
View coverage report:
Expand Down
27 changes: 27 additions & 0 deletions state/custom_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package state

import "testing"

func TestGetUbuntuMirrorByAliases(t *testing.T) {
alias := getUbuntuMirrorByAliases("cn:tsinghua")
if alias != BUILDIN_CUSTOM_UBUNTU_MIRRORS[0].url {
t.Fatal("Test Get Mirror By Custom Name Failed")
}

alias = getUbuntuMirrorByAliases("cn:not-found")
if alias != "" {
t.Fatal("Test Get Mirror By Custom Name Failed")
}
}

func TestGetDebianMirrorByAliases(t *testing.T) {
alias := getDebianMirrorByAliases("cn:tsinghua")
if alias != BUILDIN_CUSTOM_DEBIAN_MIRRORS[0].url {
t.Fatal("Test Get Mirror By Custom Name Failed")
}

alias = getDebianMirrorByAliases("cn:not-found")
if alias != "" {
t.Fatal("Test Get Mirror By Custom Name Failed")
}
}
26 changes: 16 additions & 10 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ func GetProxyMode() int {
}

func SetUbuntuMirror(input string) {
mirror := ""
if input == "" {
UBUNTU_MIRROR = nil
return
}

mirror := input
alias := getUbuntuMirrorByAliases(input)
if alias == "" {
mirror = input
} else {
if alias != "" {
mirror = alias
}

url, err := url.Parse(mirror)
if err != nil || mirror == "" {
if err != nil {
UBUNTU_MIRROR = nil
return
}
Expand All @@ -42,16 +45,19 @@ func ResetUbuntuMirror() {
}

func SetDebianMirror(input string) {
mirror := ""
if input == "" {
DEBIAN_MIRROR = nil
return
}

mirror := input
alias := getDebianMirrorByAliases(input)
if alias == "" {
mirror = input
} else {
if alias != "" {
mirror = alias
}

url, err := url.Parse(mirror)
if err != nil || mirror == "" {
if err != nil {
DEBIAN_MIRROR = nil
return
}
Expand Down

0 comments on commit 923bcd2

Please sign in to comment.