github.com/GoogleContainerTools/skaffold/v2@v2.13.2/integration/inspect_test.go (about) 1 /* 2 Copyright 2021 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 "fmt" 21 "os" 22 "path/filepath" 23 "testing" 24 25 "github.com/GoogleContainerTools/skaffold/v2/integration/skaffold" 26 "github.com/GoogleContainerTools/skaffold/v2/testutil" 27 ) 28 29 func TestInspectBuildEnv(t *testing.T) { 30 gcbParams := []string{ 31 "--projectId", "proj2", 32 "--workerPool", "projects/test/locations/asia-east1/workerPools/pool2", 33 "--timeout", "180s", 34 "--machineType", "vm2", 35 "--logStreamingOption", "STREAM_ON", 36 "--logging", "LEGACY", 37 "--diskSizeGb", "10", 38 "--concurrency", "2", 39 } 40 41 clusterParams := []string{ 42 "--concurrency", "2", 43 "--pullSecretName", "kaniko-secret2", 44 "--randomDockerConfigSecret=true", 45 "--randomPullSecret=true", 46 } 47 48 tests := []struct { 49 description string 50 inputConfigFile string 51 args []string 52 expectedConfigFile string 53 expectedOut string 54 }{ 55 { 56 description: "add new gcb build env definition in default pipeline", 57 inputConfigFile: "gcb/skaffold.local.yaml", 58 expectedConfigFile: "gcb/skaffold.add.default.yaml", 59 args: append([]string{"build-env", "add", "googleCloudBuild"}, gcbParams...), 60 }, 61 { 62 description: "add new gcb build env definition in new profile", 63 inputConfigFile: "gcb/skaffold.gcb.yaml", 64 expectedConfigFile: "gcb/skaffold.add.profile.yaml", 65 args: append([]string{"build-env", "add", "googleCloudBuild", "--profile", "gcb"}, gcbParams...), 66 }, 67 { 68 description: "modify existing gcb build env definition in default pipeline", 69 inputConfigFile: "gcb/skaffold.gcb.yaml", 70 expectedConfigFile: "gcb/skaffold.modified.default.yaml", 71 args: append([]string{"build-env", "modify", "googleCloudBuild"}, gcbParams...), 72 }, 73 { 74 description: "modify existing gcb build env definition in existing profile", 75 inputConfigFile: "gcb/skaffold.local.yaml", 76 expectedConfigFile: "gcb/skaffold.modified.profile.yaml", 77 args: append([]string{"build-env", "modify", "googleCloudBuild", "--profile", "gcb"}, gcbParams...), 78 }, 79 80 { 81 description: "add new cluster build env definition in default pipeline", 82 inputConfigFile: "cluster/skaffold.local.yaml", 83 expectedConfigFile: "cluster/skaffold.add.default.yaml", 84 args: append([]string{"build-env", "add", "cluster"}, clusterParams...), 85 }, 86 { 87 description: "add new cluster build env definition in new profile", 88 inputConfigFile: "cluster/skaffold.cluster.yaml", 89 expectedConfigFile: "cluster/skaffold.add.profile.yaml", 90 args: append([]string{"build-env", "add", "cluster", "--profile", "cluster"}, clusterParams...), 91 }, 92 } 93 94 for _, test := range tests { 95 testutil.Run(t, test.description, func(t *testutil.T) { 96 MarkIntegrationTest(t.T, CanRunWithoutGcp) 97 tmpDir := t.NewTempDir() 98 configContents, err := os.ReadFile(filepath.Join("testdata/inspect", test.inputConfigFile)) 99 t.CheckNoError(err) 100 tmpDir.Write("skaffold.yaml", string(configContents)) 101 args := append(test.args, fmt.Sprintf("-f=%s", tmpDir.Path("skaffold.yaml"))) 102 out := skaffold.Inspect(args...).InDir(tmpDir.Root()).RunOrFailOutput(t.T) 103 if test.expectedOut != "" { 104 t.CheckDeepEqual(test.expectedOut, string(out)) 105 } 106 if test.expectedConfigFile != "" { 107 expectedConfig, err := os.ReadFile(filepath.Join("testdata/inspect", test.expectedConfigFile)) 108 t.CheckNoError(err) 109 actualConfig, err := os.ReadFile(tmpDir.Path("skaffold.yaml")) 110 t.CheckNoError(err) 111 t.CheckDeepEqual(string(expectedConfig), string(actualConfig), testutil.YamlObj(t.T)) 112 } 113 }) 114 } 115 }