package icons import ( "regexp" "testing" "github.com/stretchr/testify/assert" ) func TestForImage(t *testing.T) { cases := []struct { ref, want string }{ {"gitea/gitea:1.27.3", "gitea"}, {"ghcr.io/goauthentik/server:2026.8.2", "authentik"}, {"postgres:17.10", "postgresql"}, {"grafana/loki:3.4.2", "grafana"}, {"docker.n8n.io/n8nio/n8n:1.112.4", "n8n"}, {"lscr.io/linuxserver/prowlarr:latest", ""}, {"localhost:5000/foo:v1", ""}, {"gitea.shcizo.se/shcizo/slusk:v0.8.1", ""}, } for _, c := range cases { t.Run(c.ref, func(t *testing.T) { assert.Equal(t, c.want, ForImage(c.ref)) }) } } // safePath is a strict allowlist for what an embedded path may contain, since // the paths are written into the page's HTML. var safePath = regexp.MustCompile(`^[MmLlHhVvCcSsQqTtAaZz0-9.,\- e]+$`) func TestEmbeddedSet(t *testing.T) { assert.Greater(t, Count(), 3000) for slug, p := range paths { if !safePath.MatchString(p) { t.Errorf("icon %q has unexpected characters in its path", slug) } } p, ok := Path("gitea") assert.True(t, ok) assert.NotEmpty(t, p) _, ok = Path("no-such-icon") assert.False(t, ok) }