mirror of
https://github.com/Octops/quake-kube.git
synced 2026-04-05 17:20:33 +00:00
Fixes #23, adds Tests action
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -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
internal/quake/content/router_test.go
Normal file
35
internal/quake/content/router_test.go
Normal file
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -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 ""
|
||||
@ -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
|
||||
@ -82,5 +87,4 @@ func TestConfigMarshal(t *testing.T) {
|
||||
if diff := cmp.Diff(string(data), expectedConfig); diff != "" {
|
||||
t.Fatalf(diff)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user