github.com/GoogleContainerTools/skaffold/v2@v2.13.2/integration/remote_config_dependency_test.go (about)

     1  /*
     2  Copyright 2024 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 integration
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/GoogleContainerTools/skaffold/v2/integration/skaffold"
    23  	"github.com/GoogleContainerTools/skaffold/v2/testutil"
    24  )
    25  
    26  func TestRenderWithGCBRepositoryRemoteDependency(t *testing.T) {
    27  	tests := []struct {
    28  		description    string
    29  		configFile     string
    30  		shouldErr      bool
    31  		expectedOutput string
    32  		expectedErrMsg string
    33  	}{
    34  		{
    35  			description: "GCB repository remote dependency with private git repo",
    36  			configFile: `apiVersion: skaffold/v4beta10
    37  kind: Config
    38  requires:
    39    - googleCloudBuildRepoV2:
    40        projectID: k8s-skaffold
    41        region: us-central1
    42        connection: github-connection-e2e-tests
    43        repo: skaffold-getting-started
    44  `,
    45  			expectedOutput: `apiVersion: v1
    46  kind: Pod
    47  metadata:
    48    name: getting-started
    49  spec:
    50    containers:
    51    - image: skaffold-example:fixed
    52      name: getting-started
    53  `,
    54  		},
    55  		{
    56  			description: "GCB repository remote dependency with private git repo, pointing to an specific branch",
    57  			configFile: `apiVersion: skaffold/v4beta10
    58  kind: Config
    59  requires:
    60    - googleCloudBuildRepoV2:
    61        projectID: k8s-skaffold
    62        region: us-central1
    63        connection: github-connection-e2e-tests
    64        repo: skaffold-getting-started
    65        ref: feature-branch
    66  `,
    67  			expectedOutput: `apiVersion: apps/v1
    68  kind: Deployment
    69  metadata:
    70    name: my-deployment
    71    labels:
    72      app: my-deployment
    73  spec:
    74    replicas: 1
    75    selector:
    76      matchLabels:
    77        app: my-deployment
    78    template:
    79      metadata:
    80        labels:
    81          app: my-deployment
    82      spec:
    83        containers:
    84        - name: getting-started
    85          image: skaffold-example-deployment:fixed
    86  `,
    87  		},
    88  		{
    89  			description: "GCB repository remote dependency with private git repo fails, bad configuration",
    90  			configFile: `apiVersion: skaffold/v4beta10
    91  kind: Config
    92  requires:
    93    - googleCloudBuildRepoV2:
    94        projectID: bad-repo
    95        region: us-central1
    96        connection: github-connection-e2e-tests
    97        repo: skaffold-getting-started
    98        ref: feature-branch
    99  `,
   100  			shouldErr:      true,
   101  			expectedErrMsg: "getting GCB repo info for skaffold-getting-started: failed to get remote URI for repository skaffold-getting-started",
   102  		},
   103  	}
   104  
   105  	for _, test := range tests {
   106  		testutil.Run(t, test.description, func(t *testutil.T) {
   107  			MarkIntegrationTest(t.T, NeedsGcp)
   108  			tmpDir := t.NewTempDir()
   109  			tmpDir.Write("skaffold.yaml", test.configFile)
   110  			args := []string{"--remote-cache-dir", tmpDir.Root(), "--tag", "fixed", "--default-repo=", "--digest-source", "tag"}
   111  			output, err := skaffold.Render(args...).InDir(tmpDir.Root()).RunWithCombinedOutput(t.T)
   112  
   113  			t.CheckError(test.shouldErr, err)
   114  
   115  			if !test.shouldErr {
   116  				t.CheckDeepEqual(test.expectedOutput, string(output), testutil.YamlObj(t.T))
   117  			} else {
   118  				t.CheckContains(test.expectedErrMsg, string(output))
   119  			}
   120  		})
   121  	}
   122  }