Skip to content
This repository was archived by the owner on Nov 20, 2021. It is now read-only.

Commit df74971

Browse files
committed
Fixes #23, adds Tests action
1 parent c122989 commit df74971

File tree

6 files changed

+85
-18
lines changed

6 files changed

+85
-18
lines changed

.github/workflows/test.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Install golang
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: '^1.13.1' # The Go version to download (if necessary) and use.
22+
23+
- name: Run tests
24+
run: |
25+
make test

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ build:
1919
.PHONY: buildx
2020
buildx:
2121
@docker buildx build . --platform=linux/amd64,linux/arm64 --progress=auto -t $(IMAGE) --push
22+
23+
.PHONY: test
24+
test:
25+
@go test -v ./internal/...

internal/quake/content/router.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"net/http"
88
"os"
99
"path/filepath"
10-
"regexp"
1110
"strings"
1211

1312
"github.com/labstack/echo/v4"
@@ -130,10 +129,10 @@ func NewRouter(cfg *Config) (*echo.Echo, error) {
130129
return e, nil
131130
}
132131

133-
var assetPattern = regexp.MustCompile(`(\d+-)`)
134-
135132
// trimAssetName returns a path string that has been prefixed with a crc32
136133
// checksum.
137134
func trimAssetName(s string) string {
138-
return assetPattern.ReplaceAllLiteralString(s, "")
135+
d, f := filepath.Split(s)
136+
f = f[strings.Index(f, "-")+1:]
137+
return filepath.Join(d, f)
139138
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package content
2+
3+
import (
4+
"testing"
5+
6+
"github.com/google/go-cmp/cmp"
7+
)
8+
9+
func TestTrimAssetName(t *testing.T) {
10+
cases := []struct {
11+
name string
12+
input string
13+
expected string
14+
}{
15+
{
16+
name: "root folder",
17+
input: "857908472-linuxq3ademo-1.11-6.x86.gz.sh",
18+
expected: "linuxq3ademo-1.11-6.x86.gz.sh",
19+
},
20+
{
21+
name: "pak file",
22+
input: "baseq3/2483777038-pak0.pk3",
23+
expected: "baseq3/pak0.pk3",
24+
},
25+
}
26+
27+
for _, c := range cases {
28+
t.Run(c.name, func(t *testing.T) {
29+
result := trimAssetName(c.input)
30+
if diff := cmp.Diff(c.expected, result); diff != "" {
31+
t.Errorf("content: after trimAssetName differs: (-want +got)\n%s", diff)
32+
}
33+
})
34+
}
35+
}

internal/quake/server/config_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ maps:
4343
`
4444

4545
const expectedConfig = `seta fraglimit "25"
46+
seta bot_minplayers "0"
47+
seta bot_nochat "0"
4648
seta g_forcerespawn "0"
4749
seta g_gametype "0"
4850
seta g_log ""
4951
seta g_motd "Welcome to Critical Stack"
52+
seta g_password ""
5053
seta g_quadfactor "3"
54+
seta g_spSkill "0"
5155
seta g_weaponrespawn "3"
5256
seta fs_basegame ""
5357
seta fs_basepath ""
@@ -59,15 +63,16 @@ seta sv_allowDownload "0"
5963
seta sv_hostname "quakekube"
6064
seta sv_maxclients "12"
6165
seta rconpassword "changeme"
62-
seta g_inactivity 600
63-
seta sv_timeout 120
6466
set d0 "seta g_gametype 0 ; map q3dm7 ; set nextmap vstr d1"
6567
set d1 "seta g_gametype 0 ; map q3dm17 ; set nextmap vstr d2"
6668
set d2 "seta g_gametype 4 ; capturelimit 8 ; map q3wctf1 ; set nextmap vstr d3"
6769
set d3 "seta g_gametype 1 ; map q3tourney2 ; set nextmap vstr d4"
6870
set d4 "seta g_gametype 4 ; capturelimit 8 ; map q3wctf3 ; set nextmap vstr d5"
6971
set d5 "seta g_gametype 1 ; map ztn3tourney1 ; set nextmap vstr d0"
70-
vstr d0`
72+
vstr d0
73+
seta g_inactivity 600
74+
seta sv_timeout 120
75+
`
7176

7277
func TestConfigMarshal(t *testing.T) {
7378
var cfg *Config
@@ -82,5 +87,4 @@ func TestConfigMarshal(t *testing.T) {
8287
if diff := cmp.Diff(string(data), expectedConfig); diff != "" {
8388
t.Fatalf(diff)
8489
}
85-
8690
}

public/zz_generated.static.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)