github.com/GoogleContainerTools/skaffold/v2@v2.13.2/integration/control_api_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 integration
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"strings"
    24  	"testing"
    25  	"time"
    26  
    27  	"github.com/GoogleContainerTools/skaffold/v2/integration/skaffold"
    28  	event "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/event/v2"
    29  	"github.com/GoogleContainerTools/skaffold/v2/proto/v1"
    30  )
    31  
    32  const (
    33  	testDev = "test-dev"
    34  )
    35  
    36  func TestControlAPIManualTriggers(t *testing.T) {
    37  	MarkIntegrationTest(t, CanRunWithoutGcp)
    38  
    39  	Run(t, "testdata/dev", "sh", "-c", "echo foo > foo")
    40  	defer Run(t, "testdata/dev", "rm", "foo")
    41  
    42  	ns, client := SetupNamespace(t)
    43  	out := bytes.Buffer{}
    44  	rpcAddr := randomPort()
    45  	skaffold.Dev("--auto-build=false", "--auto-sync=false", "--auto-deploy=false", "--rpc-port", rpcAddr, "--cache-artifacts=false").InDir("testdata/dev").InNs(ns.Name).RunInBackgroundWithOutput(t, &out)
    46  
    47  	rpcClient, entries := apiEvents(t, rpcAddr)
    48  
    49  	dep := client.GetDeployment(testDev)
    50  
    51  	failNowIfError(t, waitForEvent(90*time.Second, entries, func(e *proto.LogEntry) bool {
    52  		dle, ok := e.Event.EventType.(*proto.Event_DevLoopEvent)
    53  		return ok && dle.DevLoopEvent.Status == event.Succeeded
    54  	}))
    55  
    56  	// Make a change to foo
    57  	Run(t, "testdata/dev", "sh", "-c", "echo bar > foo")
    58  
    59  	// Execute dev loop trigger
    60  	rpcClient.Execute(context.Background(), &proto.UserIntentRequest{
    61  		Intent: &proto.Intent{
    62  			Devloop: true,
    63  		},
    64  	})
    65  	// Ensure we see a build triggered in the event log
    66  	err := waitForEvent(2*time.Minute, entries, func(e *proto.LogEntry) bool {
    67  		return e.GetEvent().GetBuildEvent().GetArtifact() == testDev
    68  	})
    69  	failNowIfError(t, err)
    70  	// verify deployment happened.
    71  	verifyDeployment(t, entries, client, dep)
    72  
    73  	// Make another change to foo and we should not see any event log.
    74  	Run(t, "testdata/dev", "sh", "-c", "echo bar > foo")
    75  
    76  	// Give skaffold some time to register a file change.
    77  	time.Sleep(1 * time.Second)
    78  	if c := strings.Count(out.String(), "Generating tags"); c != 2 {
    79  		failNowIfError(t, fmt.Errorf("expected to see tags generated twice (1st build and 1 trigger), saw %d times", c))
    80  	}
    81  }