github.com/tilt-dev/tilt@v0.36.0/integration/k8s_custom_deploy_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"context"
     8  	"os/exec"
     9  	"path/filepath"
    10  	"strings"
    11  	"testing"
    12  	"time"
    13  
    14  	"github.com/stretchr/testify/assert"
    15  	"github.com/stretchr/testify/require"
    16  
    17  	"github.com/tilt-dev/tilt/internal/testutils/bufsync"
    18  )
    19  
    20  func TestK8sCustomDeploy(t *testing.T) {
    21  	kubectlPath, err := exec.LookPath("kubectl")
    22  	if err != nil || kubectlPath == "" {
    23  		t.Fatal("`kubectl` not found in PATH")
    24  	}
    25  
    26  	f := newK8sFixture(t, "k8s_custom_deploy")
    27  	f.SetRestrictedCredentials()
    28  
    29  	f.TiltUp()
    30  
    31  	ctx, cancel := context.WithTimeout(f.ctx, time.Minute)
    32  	defer cancel()
    33  	f.WaitForAllPodsReady(ctx, "someLabel=someValue1")
    34  
    35  	// check that port forward is working
    36  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    37  	defer cancel()
    38  	f.CurlUntil(ctx, "http://localhost:54871", "Welcome to nginx!")
    39  
    40  	// check that pod log streaming is working (integration text fixture already streams logs to stdout,
    41  	// so assert.True is used vs assert.Contains to avoid spewing a duplicate copy on failure)
    42  	assert.True(t, strings.Contains(f.logs.String(), "start worker processes"),
    43  		"Container logs not visible on stdout")
    44  
    45  	// deploy.yaml is monitored by the FileWatch referenced by restartOn, so it should trigger
    46  	// reconciliation and the KA Cmd should get re-invoked
    47  	f.ReplaceContents("deploy.yaml", "someValue1", "someValue2")
    48  
    49  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    50  	defer cancel()
    51  	f.WaitForAllPodsReady(ctx, "someLabel=someValue2")
    52  
    53  	// verify port forward still works
    54  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    55  	defer cancel()
    56  	f.CurlUntil(ctx, "http://localhost:54871", "Welcome to nginx!")
    57  
    58  	// perform a Live Update (this version of the file can _only_ exist in the container via Live Update,
    59  	// as it's overwriting a file from a public image)
    60  	f.ReplaceContents(filepath.Join("web", "index.html"), "Hello", "Greetings")
    61  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    62  	defer cancel()
    63  	f.CurlUntil(ctx, "http://localhost:54871", "Greetings from Live Update!")
    64  
    65  	f.Touch("fallback.txt")
    66  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    67  	defer cancel()
    68  	f.CurlUntil(ctx, "http://localhost:54871", "Welcome to nginx!")
    69  
    70  	downOutput := bufsync.NewThreadSafeBuffer()
    71  	require.NoError(t, f.tilt.Down(f.ctx, downOutput), "tilt down failed")
    72  	assert.Contains(t, downOutput.String(), `deployment.apps "custom-deploy" deleted`)
    73  }