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

Commit

Permalink
Fixes #23, adds Tests action
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRx committed Nov 23, 2020
1 parent c122989 commit df74971
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 18 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install golang
uses: actions/setup-go@v2
with:
go-version: '^1.13.1' # The Go version to download (if necessary) and use.

- name: Run tests
run: |
make test
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ build:
.PHONY: buildx
buildx:
@docker buildx build . --platform=linux/amd64,linux/arm64 --progress=auto -t $(IMAGE) --push

.PHONY: test
test:
@go test -v ./internal/...
7 changes: 3 additions & 4 deletions internal/quake/content/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"

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

var assetPattern = regexp.MustCompile(`(\d+-)`)

// trimAssetName returns a path string that has been prefixed with a crc32
// checksum.
func trimAssetName(s string) string {
return assetPattern.ReplaceAllLiteralString(s, "")
d, f := filepath.Split(s)
f = f[strings.Index(f, "-")+1:]
return filepath.Join(d, f)
}
35 changes: 35 additions & 0 deletions internal/quake/content/router_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package content

import (
"testing"

"github.com/google/go-cmp/cmp"
)

func TestTrimAssetName(t *testing.T) {
cases := []struct {
name string
input string
expected string
}{
{
name: "root folder",
input: "857908472-linuxq3ademo-1.11-6.x86.gz.sh",
expected: "linuxq3ademo-1.11-6.x86.gz.sh",
},
{
name: "pak file",
input: "baseq3/2483777038-pak0.pk3",
expected: "baseq3/pak0.pk3",
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
result := trimAssetName(c.input)
if diff := cmp.Diff(c.expected, result); diff != "" {
t.Errorf("content: after trimAssetName differs: (-want +got)\n%s", diff)
}
})
}
}
12 changes: 8 additions & 4 deletions internal/quake/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ maps:
`

const expectedConfig = `seta fraglimit "25"
seta bot_minplayers "0"
seta bot_nochat "0"
seta g_forcerespawn "0"
seta g_gametype "0"
seta g_log ""
seta g_motd "Welcome to Critical Stack"
seta g_password ""
seta g_quadfactor "3"
seta g_spSkill "0"
seta g_weaponrespawn "3"
seta fs_basegame ""
seta fs_basepath ""
Expand All @@ -59,15 +63,16 @@ seta sv_allowDownload "0"
seta sv_hostname "quakekube"
seta sv_maxclients "12"
seta rconpassword "changeme"
seta g_inactivity 600
seta sv_timeout 120
set d0 "seta g_gametype 0 ; map q3dm7 ; set nextmap vstr d1"
set d1 "seta g_gametype 0 ; map q3dm17 ; set nextmap vstr d2"
set d2 "seta g_gametype 4 ; capturelimit 8 ; map q3wctf1 ; set nextmap vstr d3"
set d3 "seta g_gametype 1 ; map q3tourney2 ; set nextmap vstr d4"
set d4 "seta g_gametype 4 ; capturelimit 8 ; map q3wctf3 ; set nextmap vstr d5"
set d5 "seta g_gametype 1 ; map ztn3tourney1 ; set nextmap vstr d0"
vstr d0`
vstr d0
seta g_inactivity 600
seta sv_timeout 120
`

func TestConfigMarshal(t *testing.T) {
var cfg *Config
Expand All @@ -82,5 +87,4 @@ func TestConfigMarshal(t *testing.T) {
if diff := cmp.Diff(string(data), expectedConfig); diff != "" {
t.Fatalf(diff)
}

}
20 changes: 10 additions & 10 deletions public/zz_generated.static.go

Large diffs are not rendered by default.

0 comments on commit df74971

Please sign in to comment.