package integration import ( "context" "fmt" "os" "testing" "gotest.tools/v3/assert" whv1 "edge-infra.dev/pkg/f8n/warehouse/k8s/apis/v1alpha2" "edge-infra.dev/pkg/f8n/warehouse/k8s/controllers/lumperctl/internal" "edge-infra.dev/pkg/f8n/warehouse/oci/cache" "edge-infra.dev/pkg/k8s/runtime/conditions" "edge-infra.dev/pkg/k8s/runtime/controller/reconcile/recerr" "edge-infra.dev/test/f2" "edge-infra.dev/test/f2/x/warehouse" ) var f f2.Framework func TestMain(m *testing.M) { f = f2.New(context.Background(), f2.WithExtensions(&warehouse.Registry{})) os.Exit(f.Run(m)) } func TestFetch(t *testing.T) { feat := f2.NewFeature("Fetch"). Test("Fetch returns reconciler Errors", func(ctx f2.Context, t *testing.T) f2.Context { // create Reconciler with no caching, forcing remote Get warehouseCache, err := cache.New() assert.NilError(t, err) rec := &internal.Reconciler{ Cache: warehouseCache, } // set up reference to non-existent artifact registry := warehouse.FromContextT(ctx, t) registryRepoPath := fmt.Sprintf("%s/%s", registry.URL, "testhouse") missingRef, err := whv1.BaseArtifact{Tag: "latest", Name: "does-not-exist"}.WithRepo(registryRepoPath).Ref() assert.NilError(t, err) // Reconciler should fail to Fetch artifact, return correct error id := fmt.Sprintf("testfetch-%s", ctx.RunID) s := whv1.NewShipment(id) _, err = rec.Fetch(ctx, s, missingRef, whv1.Always) assert.ErrorContains(t, err, "404 Not Found") _, ok := err.(recerr.Error) if !ok { t.Fatalf("Fetch should return an error implementing [recerr.Error], got %T", err) } if !conditions.HasReason(s, whv1.FetchedArtifactCondition, whv1.FetchFailedReason) { t.Fatalf("expected Condition %s with Reason %s", whv1.FetchedArtifactCondition, whv1.FetchFailedReason) } return ctx }).Feature() f.Test(t, feat) }