Files
mesh-sdk/go/delivery/trunk_test.go
T

68 lines
2.8 KiB
Go

package delivery
import (
"encoding/json"
"testing"
)
func TestSameRepository(t *testing.T) { // 1281/AC1
const forge = "novox/mesh-catalog"
for _, c := range []struct {
a, b string
same bool
}{
// the clone URL as a build record carries it (mesh-controller.command builds, 2026-10-19 ~21:20 local)
{forge, "http://novox.internal:20000/novox/mesh-catalog.git", true},
{forge, "http://novox.internal:20000/novox/mesh-catalog", true},
{forge, "http://novox.internal:20000/novox/mesh-catalog.git/", true},
{"http://novox.internal:20000/novox/mesh-catalog.git/", forge, true},
{forge, "novox/mesh-catalog", true},
{forge, "Novox/Mesh-Catalog", true},
{forge, "http://novox.internal:20000/novox/mesh-catalog-x.git", false},
{forge, "novox/mesh-catalog-x", false},
{forge, "http://novox.internal:20000/other/mesh-catalog.git", false},
{forge, "other/mesh-catalog", false},
{forge, "http://novox.internal:20000/novox/mesh-media-catalog.git", false},
{forge, "", false},
{"", "", false},
} {
if got := SameRepository(c.a, c.b); got != c.same {
t.Errorf("SameRepository(%q, %q) = %v, want %v", c.a, c.b, got, c.same)
}
}
if got := RepositoryName("http://novox.internal:20000/novox/mesh-catalog.git"); got != "novox/mesh-catalog" {
t.Errorf("RepositoryName = %q", got)
}
}
func TestIsTrunkBuild(t *testing.T) { // 1281/AC2
inputs := &SourceInputs{Module: "zsh", Tree: "t"}
for _, c := range []struct {
name string
r BuildRecord
want bool
}{
{"built on main", BuildRecord{Ref: "main", SourceInputs: inputs}, true},
// a build a delivery plan asked after a merge, or rebuild / build --behind, carries no ref (live builds,
// 2026-10-19: zsh build-1792417485811374131, mesh-delivery build-1792435539606203626)
{"built with no ref", BuildRecord{SourceInputs: inputs}, true},
{"another branch", BuildRecord{Ref: "feat/x", SourceInputs: inputs}, false},
{"a commit", BuildRecord{Ref: "9efdd87a", SourceInputs: inputs}, false},
{"asked", BuildRecord{State: "asked", SourceInputs: inputs}, false},
{"answered, state built", BuildRecord{State: "built", SourceInputs: inputs}, false},
{"failed", BuildRecord{Failed: "boom", Ref: "main", SourceInputs: inputs}, false},
{"no source inputs", BuildRecord{Ref: "main"}, false},
{"no ref and no source inputs", BuildRecord{}, false},
} {
if got := c.r.IsTrunkBuild(); got != c.want {
t.Errorf("%s: IsTrunkBuild = %v, want %v", c.name, got, c.want)
}
}
// decoded as the controller writes it: the key "ref" is absent
var r BuildRecord
raw := `{"id":"build-1792417485811374131","repository":"http://novox.internal:20000/novox/mesh-catalog.git","module":"zsh","source-inputs":{"Module":"zsh","Tree":"t"}}`
if err := json.Unmarshal([]byte(raw), &r); err != nil || !r.IsTrunkBuild() {
t.Errorf("a decoded record with no ref: trunk = %v, err %v", r.IsTrunkBuild(), err)
}
}