...

Source file src/edge-infra.dev/pkg/f8n/warehouse/k8s/controllers/lumperctl/internal/integration/reconciler_test.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/k8s/controllers/lumperctl/internal/integration

     1  package integration
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"testing"
     8  
     9  	"gotest.tools/v3/assert"
    10  
    11  	whv1 "edge-infra.dev/pkg/f8n/warehouse/k8s/apis/v1alpha2"
    12  	"edge-infra.dev/pkg/f8n/warehouse/k8s/controllers/lumperctl/internal"
    13  	"edge-infra.dev/pkg/f8n/warehouse/oci/cache"
    14  	"edge-infra.dev/pkg/k8s/runtime/conditions"
    15  	"edge-infra.dev/pkg/k8s/runtime/controller/reconcile/recerr"
    16  	"edge-infra.dev/test/f2"
    17  	"edge-infra.dev/test/f2/x/warehouse"
    18  )
    19  
    20  var f f2.Framework
    21  
    22  func TestMain(m *testing.M) {
    23  	f = f2.New(context.Background(), f2.WithExtensions(&warehouse.Registry{}))
    24  	os.Exit(f.Run(m))
    25  }
    26  
    27  func TestFetch(t *testing.T) {
    28  	feat := f2.NewFeature("Fetch").
    29  		Test("Fetch returns reconciler Errors", func(ctx f2.Context, t *testing.T) f2.Context {
    30  			// create Reconciler with no caching, forcing remote Get
    31  			warehouseCache, err := cache.New()
    32  			assert.NilError(t, err)
    33  			rec := &internal.Reconciler{
    34  				Cache: warehouseCache,
    35  			}
    36  
    37  			// set up reference to non-existent artifact
    38  			registry := warehouse.FromContextT(ctx, t)
    39  			registryRepoPath := fmt.Sprintf("%s/%s", registry.URL, "testhouse")
    40  			missingRef, err := whv1.BaseArtifact{Tag: "latest", Name: "does-not-exist"}.WithRepo(registryRepoPath).Ref()
    41  			assert.NilError(t, err)
    42  
    43  			// Reconciler should fail to Fetch artifact, return correct error
    44  			id := fmt.Sprintf("testfetch-%s", ctx.RunID)
    45  			s := whv1.NewShipment(id)
    46  			_, err = rec.Fetch(ctx, s, missingRef, whv1.Always)
    47  			assert.ErrorContains(t, err, "404 Not Found")
    48  			_, ok := err.(recerr.Error)
    49  			if !ok {
    50  				t.Fatalf("Fetch should return an error implementing [recerr.Error], got %T", err)
    51  			}
    52  
    53  			if !conditions.HasReason(s, whv1.FetchedArtifactCondition, whv1.FetchFailedReason) {
    54  				t.Fatalf("expected Condition %s with Reason %s", whv1.FetchedArtifactCondition, whv1.FetchFailedReason)
    55  			}
    56  
    57  			return ctx
    58  		}).Feature()
    59  
    60  	f.Test(t, feat)
    61  }
    62  

View as plain text