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

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"context"
     8  	"path/filepath"
     9  	"strings"
    10  	"testing"
    11  	"time"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestLiveUpdateOnly(t *testing.T) {
    17  	f := newK8sFixture(t, "live_update_only")
    18  	f.SetRestrictedCredentials()
    19  
    20  	f.TiltUp()
    21  
    22  	// ForwardPort will fail if all the pods are not ready.
    23  	//
    24  	// We can't use the normal Tilt-managed forwards here because
    25  	// Tilt doesn't setup forwards when --watch=false.
    26  	ctx, cancel := context.WithTimeout(f.ctx, time.Minute)
    27  	defer cancel()
    28  	f.WaitForAllPodsReady(ctx, "app=lu-only")
    29  
    30  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    31  	defer cancel()
    32  	// since we're using a public image, until we modify a file, the original contents are there
    33  	f.CurlUntil(ctx, "http://localhost:28195", "Welcome to nginx!")
    34  
    35  	f.ReplaceContents(filepath.Join("web", "index.html"), "Hello", "Greetings")
    36  
    37  	// verify file was changed (we know it's the same pod because this file can ONLY exist via Live Update sync)
    38  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    39  	defer cancel()
    40  	f.CurlUntil(ctx, "http://localhost:28195", "Greetings from Live Update!")
    41  
    42  	f.ReplaceContents("special.txt",
    43  		"this file triggers a full rebuild",
    44  		"time to rebuild!")
    45  
    46  	// TODO(milas): this is ridiculously hacky - we should use `tilt wait` once that exists
    47  	// 	or otherwise poll the API manually instead of playing with log strings
    48  	var logs strings.Builder
    49  	assert.Eventually(t, func() bool {
    50  		logs.WriteString(f.logs.String())
    51  
    52  		logStr := logs.String()
    53  		fileChangeIdx := strings.Index(logStr, `1 File Changed: [special.txt]`)
    54  		if fileChangeIdx == -1 {
    55  			return false
    56  		}
    57  
    58  		afterFileChangeLogs := logStr[fileChangeIdx:]
    59  		return strings.Contains(afterFileChangeLogs, `STEP 1/1 — Deploying`)
    60  	}, 15*time.Second, 500*time.Millisecond, "Full rebuild never triggered")
    61  
    62  	// attempt another Live Update
    63  	f.ReplaceContents(filepath.Join("web", "index.html"), "Greetings", "Salutations")
    64  	ctx, cancel = context.WithTimeout(f.ctx, 10*time.Second)
    65  	defer cancel()
    66  	f.CurlUntil(ctx, "http://localhost:28195", "Salutations from Live Update!")
    67  }