mirror of
https://github.com/Octops/quake-kube.git
synced 2026-04-11 12: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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user