github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/gcb/spec_test.go (about)

     1  /*
     2  Copyright 2019 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package gcb
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
    24  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
    25  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform"
    26  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
    27  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
    28  	"github.com/GoogleContainerTools/skaffold/testutil"
    29  )
    30  
    31  func TestBuildSpecFail(t *testing.T) {
    32  	tests := []struct {
    33  		description string
    34  		artifact    *latest.Artifact
    35  	}{
    36  		{
    37  			description: "bazel",
    38  			artifact: &latest.Artifact{
    39  				ArtifactType: latest.ArtifactType{
    40  					BazelArtifact: &latest.BazelArtifact{},
    41  				},
    42  			},
    43  		},
    44  		{
    45  			description: "unknown",
    46  			artifact:    &latest.Artifact{},
    47  		},
    48  	}
    49  	for _, test := range tests {
    50  		testutil.Run(t, test.description, func(t *testutil.T) {
    51  			builder := NewBuilder(&mockBuilderContext{}, &latest.GoogleCloudBuild{})
    52  
    53  			_, err := builder.buildSpec(context.Background(), test.artifact, "tag", platform.Matcher{}, "bucket", "object")
    54  
    55  			t.CheckError(true, err)
    56  		})
    57  	}
    58  }
    59  
    60  type mockBuilderContext struct {
    61  	runcontext.RunContext // Embedded to provide the default values.
    62  	artifactStore         build.ArtifactStore
    63  	sourceDepsResolver    func() graph.SourceDependenciesCache
    64  }
    65  
    66  func (c *mockBuilderContext) SourceDependenciesResolver() graph.SourceDependenciesCache {
    67  	if c.sourceDepsResolver != nil {
    68  		return c.sourceDepsResolver()
    69  	}
    70  	return nil
    71  }
    72  
    73  func (c *mockBuilderContext) ArtifactStore() build.ArtifactStore { return c.artifactStore }