github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/build/boil_runs_test.go (about) 1 package build 2 3 import ( 4 "path/filepath" 5 "runtime" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 10 "github.com/tilt-dev/tilt/pkg/model" 11 ) 12 13 func TestBoilRunsNoTrigger(t *testing.T) { 14 runs := []model.Run{ 15 model.Run{ 16 Cmd: model.ToUnixCmd("echo hello"), 17 }, 18 } 19 20 pathMappings := []PathMapping{ 21 PathMapping{ 22 LocalPath: AbsPath("test", "foo"), 23 ContainerPath: "/src/foo", 24 }, 25 } 26 27 expected := []model.Cmd{model.ToUnixCmd("echo hello")} 28 29 actual, err := BoilRuns(runs, pathMappings) 30 if err != nil { 31 t.Fatal(err) 32 } 33 34 assert.ElementsMatch(t, expected, actual) 35 } 36 37 func TestBoilRunsNoFilesChanged(t *testing.T) { 38 runs := []model.Run{ 39 model.Run{ 40 Cmd: model.ToUnixCmd("echo hello"), 41 }, 42 } 43 44 pathMappings := []PathMapping{} 45 46 expected := []model.Cmd{model.ToUnixCmd("echo hello")} 47 48 actual, err := BoilRuns(runs, pathMappings) 49 if err != nil { 50 t.Fatal(err) 51 } 52 53 assert.ElementsMatch(t, expected, actual) 54 } 55 56 func TestBoilRunsOneTriggerFilesDontMatch(t *testing.T) { 57 triggers := []string{"bar"} 58 runs := []model.Run{ 59 model.Run{ 60 Cmd: model.ToUnixCmd("echo hello"), 61 Triggers: model.NewPathSet(triggers, AbsPath("test")), 62 }, 63 } 64 65 pathMappings := []PathMapping{ 66 PathMapping{ 67 LocalPath: AbsPath("test", "foo"), 68 ContainerPath: "/src/foo", 69 }, 70 } 71 72 expected := []model.Cmd{} 73 74 actual, err := BoilRuns(runs, pathMappings) 75 if err != nil { 76 t.Fatal(err) 77 } 78 79 assert.ElementsMatch(t, expected, actual) 80 } 81 82 func TestBoilRunsOneTriggerMatchingFile(t *testing.T) { 83 triggers := []string{"bar"} 84 runs := []model.Run{ 85 model.Run{ 86 Cmd: model.ToUnixCmd("echo world"), 87 Triggers: model.NewPathSet(triggers, AbsPath("test")), 88 }, 89 } 90 91 pathMappings := []PathMapping{ 92 PathMapping{ 93 LocalPath: AbsPath("test", "bar"), 94 ContainerPath: "/src/bar", 95 }, 96 } 97 98 expected := []model.Cmd{model.ToUnixCmd("echo world")} 99 100 actual, err := BoilRuns(runs, pathMappings) 101 if err != nil { 102 t.Fatal(err) 103 } 104 105 assert.ElementsMatch(t, expected, actual) 106 } 107 108 func TestBoilRunsTriggerMatchingAbsPath(t *testing.T) { 109 triggers := []string{AbsPath("test", "bar")} 110 runs := []model.Run{ 111 model.Run{ 112 Cmd: model.ToUnixCmd("echo world"), 113 Triggers: model.NewPathSet(triggers, AbsPath("test")), 114 }, 115 } 116 117 pathMappings := []PathMapping{ 118 PathMapping{ 119 LocalPath: AbsPath("test", "bar"), 120 ContainerPath: "/src/bar", 121 }, 122 } 123 124 expected := []model.Cmd{model.ToUnixCmd("echo world")} 125 126 actual, err := BoilRuns(runs, pathMappings) 127 if err != nil { 128 t.Fatal(err) 129 } 130 131 assert.ElementsMatch(t, expected, actual) 132 } 133 134 func TestBoilRunsTriggerNestedPathNoMatch(t *testing.T) { 135 triggers := []string{"bar"} 136 runs := []model.Run{ 137 model.Run{ 138 Cmd: model.ToUnixCmd("echo world"), 139 Triggers: model.NewPathSet(triggers, AbsPath("test")), 140 }, 141 } 142 143 pathMappings := []PathMapping{ 144 PathMapping{ 145 LocalPath: "/home/tilt/code/test/nested/bar", 146 ContainerPath: "/src/bar", 147 }, 148 } 149 150 expected := []model.Cmd{} 151 152 actual, err := BoilRuns(runs, pathMappings) 153 if err != nil { 154 t.Fatal(err) 155 } 156 157 assert.ElementsMatch(t, expected, actual) 158 } 159 160 func TestBoilRunsManyTriggersManyFiles(t *testing.T) { 161 wd := AbsPath("test") 162 triggers1 := []string{"foo"} 163 triggers2 := []string{"bar"} 164 runs := []model.Run{ 165 model.Run{ 166 Cmd: model.ToUnixCmd("echo hello"), 167 Triggers: model.NewPathSet(triggers1, wd), 168 }, 169 model.Run{ 170 Cmd: model.ToUnixCmd("echo world"), 171 Triggers: model.NewPathSet(triggers2, wd), 172 }, 173 } 174 175 pathMappings := []PathMapping{ 176 PathMapping{ 177 LocalPath: AbsPath("test", "baz"), 178 ContainerPath: "/src/baz", 179 }, 180 PathMapping{ 181 LocalPath: AbsPath("test", "bar"), 182 ContainerPath: "/src/bar", 183 }, 184 } 185 186 expected := []model.Cmd{model.ToUnixCmd("echo world")} 187 188 actual, err := BoilRuns(runs, pathMappings) 189 if err != nil { 190 t.Fatal(err) 191 } 192 193 assert.ElementsMatch(t, expected, actual) 194 } 195 196 func AbsPath(parts ...string) string { 197 if runtime.GOOS == "windows" { 198 return filepath.Join(append([]string{"C:\\home\\tilt"}, parts...)...) 199 } 200 return filepath.Join(append([]string{"/home/tilt"}, parts...)...) 201 }