48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package preflight
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/aritmolab/thothii/tools/tht/internal/compose"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type localDocker struct {
|
|
fakeDocker
|
|
wrong bool
|
|
}
|
|
|
|
func (d *localDocker) Run(ctx context.Context, args []string, input io.Reader) (compose.Result, error) {
|
|
if args[0] != "image" {
|
|
return d.fakeDocker.Run(ctx, args, input)
|
|
}
|
|
revision := strings.Repeat("b", 40)
|
|
if d.wrong {
|
|
revision = strings.Repeat("c", 40)
|
|
}
|
|
value, _ := json.Marshal(map[string]any{"Id": args[len(args)-1], "Os": "linux", "Architecture": "amd64", "Config": map[string]any{"Labels": map[string]string{"org.opencontainers.image.revision": revision, "org.opencontainers.image.version": "1.0.0"}}})
|
|
return compose.Result{Stdout: string(value)}, nil
|
|
}
|
|
func TestSourceImagesNeedExplicitDistributionAndMatchingLocalIdentity(t *testing.T) {
|
|
m := Manifest{Distribution: "source", Revision: strings.Repeat("b", 40), Version: "1.0.0", Images: map[string]map[string]string{}}
|
|
for _, role := range []string{"core", "frontend", "catalog", "qdrant", "embedding"} {
|
|
ref := "docker.io/example/" + role + "@sha256:" + strings.Repeat("a", 64)
|
|
if role == "core" || role == "frontend" {
|
|
ref = "sha256:" + strings.Repeat("a", 64)
|
|
}
|
|
m.Images[role] = map[string]string{"linux/amd64": ref}
|
|
}
|
|
if !CheckImages(context.Background(), &localDocker{}, m, "linux/amd64").OK {
|
|
t.Fatal("explicit local images rejected")
|
|
}
|
|
if CheckImages(context.Background(), &localDocker{wrong: true}, m, "linux/amd64").OK {
|
|
t.Fatal("different source accepted")
|
|
}
|
|
m.Distribution = ""
|
|
if CheckImages(context.Background(), &localDocker{}, m, "linux/amd64").OK {
|
|
t.Fatal("implicit source fallback accepted")
|
|
}
|
|
}
|