github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tiltfile/custom_build_test.go (about) 1 package tiltfile 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestCustomBuildImageDeps(t *testing.T) { 10 f := newFixture(t) 11 12 f.file("Tiltfile", ` 13 custom_build( 14 'base', 15 'build.sh', 16 ['.'] 17 ) 18 custom_build( 19 'fe', 20 'build.sh', 21 ['.'], 22 image_deps=['base'], 23 ) 24 k8s_yaml('fe.yaml') 25 `) 26 f.file("Dockerfile", "FROM alpine") 27 f.yaml("fe.yaml", deployment("fe", image("fe"))) 28 29 f.load() 30 31 m := f.assertNextManifest("fe") 32 if assert.Equal(t, 2, len(m.ImageTargets)) { 33 assert.Equal(t, []string{"base"}, m.ImageTargets[1].CustomBuildInfo().ImageMaps) 34 } 35 } 36 37 func TestCustomBuildMissingImageDeps(t *testing.T) { 38 f := newFixture(t) 39 40 f.file("Tiltfile", ` 41 custom_build( 42 'fe', 43 'build.sh', 44 ['.'], 45 image_deps=['base'], 46 ) 47 k8s_yaml('fe.yaml') 48 `) 49 f.file("Dockerfile", "FROM alpine") 50 f.yaml("fe.yaml", deployment("fe", image("fe"))) 51 52 f.loadErrString(`image "fe": image dep "base" not found`) 53 } 54 55 func TestCustomBuildImageWithEnv(t *testing.T) { 56 f := newFixture(t) 57 58 f.file("Tiltfile", ` 59 custom_build('custom', 'build.sh', ['.'], env={'SETTING': 'value'}) 60 61 k8s_yaml('fe.yaml') 62 `) 63 f.file("Dockerfile", `FROM alpine`) 64 f.yaml("fe.yaml", deployment("fe", image("custom"))) 65 66 f.load() 67 68 m := f.assertNextManifest("fe") 69 if assert.Equal(t, 1, len(m.ImageTargets)) { 70 cb := m.ImageTargets[0].CustomBuildInfo() 71 expected := []string{"SETTING=value"} 72 assert.Equal(t, expected, cb.CmdImageSpec.Env) 73 assert.Equal(t, f.Path(), cb.CmdImageSpec.Dir) 74 } 75 } 76 77 func TestCustomBuildImageWithDir(t *testing.T) { 78 f := newFixture(t) 79 80 f.file("Tiltfile", ` 81 custom_build('custom', 'build.sh', ['.'], dir='./subdir') 82 83 k8s_yaml('fe.yaml') 84 `) 85 f.file("Dockerfile", `FROM alpine`) 86 f.yaml("fe.yaml", deployment("fe", image("custom"))) 87 88 f.load() 89 90 m := f.assertNextManifest("fe") 91 if assert.Equal(t, 1, len(m.ImageTargets)) { 92 cb := m.ImageTargets[0].CustomBuildInfo() 93 assert.Equal(t, f.JoinPath("subdir"), cb.CmdImageSpec.Dir) 94 } 95 }