package fixtures import ( "embed" "fmt" "io/fs" "path/filepath" "edge-infra.dev/pkg/f8n/warehouse/oci/layout" "edge-infra.dev/pkg/f8n/warehouse/oci/name" "edge-infra.dev/pkg/f8n/warehouse/oci/remote" "edge-infra.dev/pkg/lib/build/bazel" ) // This file contains utilities for loading the vendored test fixtures for OCI // packages, so they can be used as test data or installing packages to K8s // clusters during testing. //go:embed warehouse/layout/** var warehouseLayout embed.FS type Path struct { *layout.Path } // Layout copies the embedded Image Layout to a test's temp directory and then // instantiates it. func Layout() (*Path, error) { testdir, err := bazel.NewTestTmpDir("edge-infra-warehouse-*") if err != nil { return nil, fmt.Errorf("failed to resolve tmp dir for image layout: %w", err) } f, err := fs.Sub(warehouseLayout, "warehouse/layout") if err != nil { return nil, fmt.Errorf("failed to create layout filesystem: %w", err) } p, err := layout.FromFS(f, filepath.Join(testdir, "warehouse/layout")) return &Path{Path: p}, err } // Push pushes an artifact from the Image Layout identified by package name and // tag to a remote registry func (p *Path) Push(dst name.Reference, pkg, tag string, opts ...remote.Option) error { ref, err := name.Tag(fmt.Sprintf("%s:%s", pkg, tag)) if err != nil { return err } oart, err := p.Get(ref) if err != nil { return fmt.Errorf("%w", err) } return remote.Write(oart, dst, opts...) }