Skip to content

Commit 9392d55

Browse files
committed
test: improve project coverage
1 parent c5fbde5 commit 9392d55

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

internal/mirrors/mirrors_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,34 @@ func TestGetPredefinedConfiguration(t *testing.T) {
6565
if res != Define.UBUNTU_BENCHMAKR_URL {
6666
t.Fatal("Failed to get resource link")
6767
}
68-
if !pattern.MatchString("http://archive.ubuntu.com/ubuntu/InRelease") {
68+
if !pattern.MatchString("/ubuntu/InRelease") {
6969
t.Fatal("Failed to verify domain name rules")
7070
}
71-
if !pattern.MatchString("http://ab.archive.ubuntu.com/ubuntu/InRelease") {
72-
t.Fatal("Failed to verify domain name rules")
73-
}
74-
if pattern.MatchString("http://abc.archive.ubuntu.com/ubuntu/InRelease") {
71+
if !pattern.MatchString("/ubuntu/InRelease") {
7572
t.Fatal("Failed to verify domain name rules")
7673
}
7774

7875
res, pattern = GetPredefinedConfiguration(Define.TYPE_LINUX_DISTROS_DEBIAN)
7976
if res != Define.DEBIAN_BENCHMAKR_URL {
8077
t.Fatal("Failed to get resource link")
8178
}
82-
if !pattern.MatchString("http://deb.debian.org/debian/InRelease") {
79+
if !pattern.MatchString("/debian/InRelease") {
80+
t.Fatal("Failed to verify domain name rules")
81+
}
82+
83+
res, pattern = GetPredefinedConfiguration(Define.TYPE_LINUX_DISTROS_CENTOS)
84+
if res != Define.CENTOS_BENCHMAKR_URL {
85+
t.Fatal("Failed to get resource link")
86+
}
87+
if !pattern.MatchString("/centos/test/repomd.xml") {
88+
t.Fatal("Failed to verify domain name rules")
89+
}
90+
91+
res, pattern = GetPredefinedConfiguration(Define.TYPE_LINUX_DISTROS_ALPINE)
92+
if res != Define.ALPINE_BENCHMAKR_URL {
93+
t.Fatal("Failed to get resource link")
94+
}
95+
if !pattern.MatchString("/alpine/test/APKINDEX.tar.gz") {
8396
t.Fatal("Failed to verify domain name rules")
8497
}
8598
}

internal/rewriter/rewriter_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package rewriter
22

33
import (
4+
"fmt"
45
"strings"
56
"testing"
67
"time"
@@ -118,7 +119,8 @@ func TestMatchingRule(t *testing.T) {
118119

119120
func TestRuleToString(t *testing.T) {
120121
rule, _ := MatchingRule("http://archive.ubuntu.com/ubuntu/InRelease", Define.UBUNTU_DEFAULT_CACHE_RULES)
121-
if rule.String() != "Release(\\.gpg)?$ Cache-Control=max-age=3600 Rewrite=true" {
122+
fmt.Println(rule.String())
123+
if rule.String() != "InRelease$ Cache-Control=max-age=3600 Rewrite=true" {
122124
t.Fatal("test rules toString faild")
123125
}
124126
}

0 commit comments

Comments
 (0)