Skip to content

Commit

Permalink
test: fix how some errors are handled (#6075)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks authored Mar 13, 2023
1 parent a48da2d commit fea33f1
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions internal/engine/upper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ type fakeBuildAndDeployer struct {

var _ buildcontrol.BuildAndDeployer = &fakeBuildAndDeployer{}

func (b *fakeBuildAndDeployer) nextImageBuildResult(ctx context.Context, iTarget model.ImageTarget) store.ImageBuildResult {
b.t.Helper()

func (b *fakeBuildAndDeployer) nextImageBuildResult(ctx context.Context, iTarget model.ImageTarget) (store.ImageBuildResult, error) {
var clusterNN types.NamespacedName
if iTarget.IsDockerBuild() {
clusterNN = types.NamespacedName{Name: iTarget.DockerBuildInfo().Cluster}
Expand All @@ -263,22 +261,27 @@ func (b *fakeBuildAndDeployer) nextImageBuildResult(ctx context.Context, iTarget
} else if iTarget.IsDockerComposeBuild() {
clusterNN = types.NamespacedName{Name: v1alpha1.ClusterNameDocker}
} else {
require.Failf(b.t, "Unknown build type", "ImageTarget: %s", iTarget.ID().String())
return store.ImageBuildResult{}, fmt.Errorf("Unknown build type. ImageTarget: %s", iTarget.ID().String())
}

if clusterNN.Name == "" {
clusterNN.Name = v1alpha1.ClusterNameDefault
}

var cluster v1alpha1.Cluster
require.NoError(b.t, b.ctrlClient.Get(ctx, clusterNN, &cluster))
err := b.ctrlClient.Get(ctx, clusterNN, &cluster)
if err != nil {
return store.ImageBuildResult{}, err
}
refs, err := iTarget.Refs(&cluster)
require.NoError(b.t, err, "Determining refs")
if err != nil {
return store.ImageBuildResult{}, fmt.Errorf("determining refs: %v", err)
}

tag := fmt.Sprintf("tilt-%d", b.buildCount)
localRefTagged := container.MustWithTag(refs.LocalRef(), tag)
clusterRefTagged := container.MustWithTag(refs.ClusterRef(), tag)
return store.NewImageBuildResult(iTarget.ID(), localRefTagged, clusterRefTagged)
return store.NewImageBuildResult(iTarget.ID(), localRefTagged, clusterRefTagged), nil
}

func (b *fakeBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, state store.BuildStateSet) (brs store.BuildResultSet, err error) {
Expand Down Expand Up @@ -347,7 +350,10 @@ func (b *fakeBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RSto
err = queue.RunBuilds(func(target model.TargetSpec, depResults []store.ImageBuildResult) (store.ImageBuildResult, error) {
b.t.Helper()
iTarget := target.(model.ImageTarget)
ibr := b.nextImageBuildResult(ctx, iTarget)
ibr, err := b.nextImageBuildResult(ctx, iTarget)
if err != nil {
return store.ImageBuildResult{}, err
}

var im v1alpha1.ImageMap
if err := b.ctrlClient.Get(ctx, types.NamespacedName{Name: iTarget.ImageMapName()}, &im); err != nil {
Expand Down

0 comments on commit fea33f1

Please sign in to comment.