github.com/GoogleContainerTools/skaffold/v2@v2.13.2/integration/dev_dependencies_test.go (about) 1 /* 2 Copyright 2020 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 "time" 22 23 "k8s.io/apimachinery/pkg/util/wait" 24 25 "github.com/GoogleContainerTools/skaffold/v2/integration/skaffold" 26 "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/constants" 27 event "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/event/v2" 28 V2proto "github.com/GoogleContainerTools/skaffold/v2/proto/v2" 29 ) 30 31 func TestDev_WithDependencies(t *testing.T) { 32 t.Run("required artifact rebuild & redeploy also rebuilds & redeploys dependencies", func(t *testing.T) { 33 MarkIntegrationTest(t, CanRunWithoutGcp) 34 ns, client := SetupNamespace(t) 35 36 rpcAddr := randomPort() 37 skaffold.Dev("--rpc-port", rpcAddr).InDir("testdata/build-dependencies").InNs(ns.Name).RunBackground(t) 38 client.waitForDeploymentsToStabilizeWithTimeout(3*time.Minute, "app1", "app2", "app3", "app4") 39 40 _, entries := v2apiEvents(t, rpcAddr) 41 42 failNowIfError(t, waitForV2Event(90*time.Second, entries, func(e *V2proto.Event) bool { 43 taskEvent, ok := e.EventType.(*V2proto.Event_TaskEvent) 44 return ok && taskEvent.TaskEvent.Task == string(constants.DevLoop) && taskEvent.TaskEvent.Status == event.Succeeded 45 })) 46 47 dep1 := client.GetDeployment("app1") 48 dep2 := client.GetDeployment("app2") 49 dep3 := client.GetDeployment("app3") 50 dep4 := client.GetDeployment("app4") 51 52 // Make a change to app3/foo so that dev is forced to delete the Deployment and redeploy app1, app2 and app3, 53 // since app2 depends on app3 and app1 depends on app2 54 Run(t, "testdata/build-dependencies/app3", "sh", "-c", "echo bar > foo") 55 defer Run(t, "testdata/build-dependencies/app3", "sh", "-c", "> foo") 56 client.waitForDeploymentsToStabilizeWithTimeout(3*time.Minute, "app1", "app2", "app3", "app4") 57 58 // Make sure the old Deployment and the new Deployment are different 59 err := wait.PollImmediate(5*time.Second, 5*time.Minute, func() (bool, error) { 60 newDep1 := client.GetDeployment("app1") 61 newDep2 := client.GetDeployment("app2") 62 newDep3 := client.GetDeployment("app3") 63 newDep4 := client.GetDeployment("app4") 64 t.Logf("app1 - old gen: %d, new gen: %d", dep1.GetGeneration(), newDep1.GetGeneration()) 65 t.Logf("app2 - old gen: %d, new gen: %d", dep2.GetGeneration(), newDep2.GetGeneration()) 66 t.Logf("app3 - old gen: %d, new gen: %d", dep3.GetGeneration(), newDep3.GetGeneration()) 67 t.Logf("app4 - old gen: %d, new gen: %d", dep4.GetGeneration(), newDep4.GetGeneration()) 68 return dep1.GetGeneration() != newDep1.GetGeneration() && 69 dep2.GetGeneration() != newDep2.GetGeneration() && 70 dep3.GetGeneration() != newDep3.GetGeneration() && 71 dep4.GetGeneration() == newDep4.GetGeneration(), nil 72 }) 73 failNowIfError(t, err) 74 }) 75 }