Conflicts: - CLAUDE.md: keep both sets of gotchas (drift/merge from main, SSE ping and swarm_cluster_id from this branch). - internal/imageref/imageref_test.go: keep both TestIsDigest (main) and TestIsRegistryHost (this branch). - internal/master/web/server.go: take main's renderServiceError and make it render through s.page, so service error pages get the sidebar nav data. Also renumber this branch's migration 0005_agent_cluster.sql to 0006_agent_cluster.sql, after main's 0005_drift_merge.sql. Claude-Session: https://claude.ai/code/session_01GAZsp3P7Qto6JnhipxWUJQ
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package imageref
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want Ref
|
|
}{
|
|
{"postgres", Ref{Repo: "postgres"}},
|
|
{"postgres:17.10", Ref{Repo: "postgres", Tag: "17.10"}},
|
|
{"gitea/gitea:1.27.3@sha256:87a6", Ref{Repo: "gitea/gitea", Tag: "1.27.3", Digest: "sha256:87a6"}},
|
|
{"lscr.io/linuxserver/jellyfin@sha256:0f42", Ref{Repo: "lscr.io/linuxserver/jellyfin", Digest: "sha256:0f42"}},
|
|
{"localhost:5000/foo", Ref{Repo: "localhost:5000/foo"}},
|
|
{"localhost:5000/foo:v1", Ref{Repo: "localhost:5000/foo", Tag: "v1"}},
|
|
{"localhost:5000/foo:v1@sha256:ab", Ref{Repo: "localhost:5000/foo", Tag: "v1", Digest: "sha256:ab"}},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.in, func(t *testing.T) {
|
|
got := Parse(c.in)
|
|
assert.Equal(t, c.want, got)
|
|
assert.Equal(t, c.in, got.String(), "String must round-trip")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIsRegistryHost(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want bool
|
|
}{
|
|
{"lscr.io", true},
|
|
{"localhost:5000", true},
|
|
{"localhost", true},
|
|
{"registry:5000", true},
|
|
{"gitea", false},
|
|
{"library", false},
|
|
{"", false},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.in, func(t *testing.T) {
|
|
assert.Equal(t, c.want, IsRegistryHost(c.in))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIsDigest(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want bool
|
|
}{
|
|
{"sha256:" + strings.Repeat("a", 64), true},
|
|
{"sha256:" + strings.Repeat("a", 63), false},
|
|
{"sha256:" + strings.Repeat("A", 64), false},
|
|
{"sha512:" + strings.Repeat("a", 64), false},
|
|
{"", false},
|
|
}
|
|
for _, c := range cases {
|
|
assert.Equal(t, c.want, IsDigest(c.in), c.in)
|
|
}
|
|
}
|