|
1 | 1 | package pipelines |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "context" |
5 | | - "github.com/loft-sh/devspace/pkg/devspace/context/values" |
6 | | - "github.com/onsi/ginkgo/v2" |
| 6 | + "io" |
7 | 7 | "os" |
8 | 8 | "time" |
9 | 9 |
|
| 10 | + "github.com/loft-sh/devspace/pkg/devspace/context/values" |
| 11 | + logpkg "github.com/loft-sh/devspace/pkg/util/log" |
| 12 | + "github.com/onsi/ginkgo/v2" |
| 13 | + "github.com/onsi/gomega" |
| 14 | + "github.com/sirupsen/logrus" |
| 15 | + |
10 | 16 | "github.com/loft-sh/devspace/cmd" |
11 | 17 | "github.com/loft-sh/devspace/cmd/flags" |
12 | 18 | "github.com/loft-sh/devspace/e2e/framework" |
@@ -166,6 +172,136 @@ var _ = DevSpaceDescribe("pipelines", func() { |
166 | 172 | } |
167 | 173 | }) |
168 | 174 |
|
| 175 | + ginkgo.It("should watch files with excludes, no ./", func(ctx context.Context) { |
| 176 | + tempDir, err := framework.CopyToTempDir("tests/pipelines/testdata/run_watch") |
| 177 | + framework.ExpectNoError(err) |
| 178 | + ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tempDir) |
| 179 | + |
| 180 | + ns, err := kubeClient.CreateNamespace("pipelines") |
| 181 | + framework.ExpectNoError(err) |
| 182 | + ginkgo.DeferCleanup(framework.ExpectDeleteNamespace, kubeClient, ns) |
| 183 | + |
| 184 | + done := make(chan error) |
| 185 | + cancelCtx, cancel := context.WithCancel(ctx) |
| 186 | + ginkgo.DeferCleanup(cancel) |
| 187 | + |
| 188 | + output := &bytes.Buffer{} |
| 189 | + multiWriter := io.MultiWriter(output, os.Stdout) |
| 190 | + log := logpkg.NewStreamLogger(multiWriter, multiWriter, logrus.DebugLevel) |
| 191 | + |
| 192 | + go func() { |
| 193 | + devCmd := &cmd.RunPipelineCmd{ |
| 194 | + GlobalFlags: &flags.GlobalFlags{ |
| 195 | + NoWarn: true, |
| 196 | + Namespace: ns, |
| 197 | + }, |
| 198 | + Pipeline: "no-dot-slash-exclude", |
| 199 | + Ctx: cancelCtx, |
| 200 | + Log: log, |
| 201 | + } |
| 202 | + err := devCmd.RunDefault(f) |
| 203 | + if err != nil { |
| 204 | + f.GetLog().Errorf("error: %v", err) |
| 205 | + } |
| 206 | + done <- err |
| 207 | + }() |
| 208 | + |
| 209 | + gomega.Eventually(func(g gomega.Gomega) { |
| 210 | + g.Expect(output.String()).Should(gomega.ContainSubstring("Start watching")) |
| 211 | + }). |
| 212 | + WithTimeout(5 * time.Second). |
| 213 | + Should(gomega.Succeed()) |
| 214 | + |
| 215 | + err = os.WriteFile("foo1/test.txt", []byte("abc.txt"), 0777) |
| 216 | + framework.ExpectNoError(err) |
| 217 | + |
| 218 | + gomega.Eventually(func(g gomega.Gomega) { |
| 219 | + g.Expect(output.String()).Should(gomega.ContainSubstring("Restarting command because 'foo1/test.txt' has changed")) |
| 220 | + }). |
| 221 | + WithTimeout(5 * time.Second). |
| 222 | + Should(gomega.Succeed()) |
| 223 | + |
| 224 | + err = os.WriteFile("foo2/test.txt", []byte("abc.txt"), 0777) |
| 225 | + framework.ExpectNoError(err) |
| 226 | + |
| 227 | + gomega.Consistently(func(g gomega.Gomega) { |
| 228 | + g.Expect(output.String()).ShouldNot(gomega.ContainSubstring("Restarting command because 'foo2/test.txt' has changed")) |
| 229 | + }). |
| 230 | + WithTimeout(5 * time.Second). |
| 231 | + Should(gomega.Succeed()) |
| 232 | + |
| 233 | + cancel() |
| 234 | + err = <-done |
| 235 | + if err != nil && err != context.Canceled { |
| 236 | + framework.ExpectNoError(err) |
| 237 | + } |
| 238 | + }) |
| 239 | + |
| 240 | + ginkgo.It("should watch files with excludes, with ./", func(ctx context.Context) { |
| 241 | + tempDir, err := framework.CopyToTempDir("tests/pipelines/testdata/run_watch") |
| 242 | + framework.ExpectNoError(err) |
| 243 | + ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tempDir) |
| 244 | + |
| 245 | + ns, err := kubeClient.CreateNamespace("pipelines") |
| 246 | + framework.ExpectNoError(err) |
| 247 | + ginkgo.DeferCleanup(framework.ExpectDeleteNamespace, kubeClient, ns) |
| 248 | + |
| 249 | + done := make(chan error) |
| 250 | + cancelCtx, cancel := context.WithCancel(ctx) |
| 251 | + ginkgo.DeferCleanup(cancel) |
| 252 | + |
| 253 | + output := &bytes.Buffer{} |
| 254 | + multiWriter := io.MultiWriter(output, os.Stdout) |
| 255 | + log := logpkg.NewStreamLogger(multiWriter, multiWriter, logrus.DebugLevel) |
| 256 | + |
| 257 | + go func() { |
| 258 | + devCmd := &cmd.RunPipelineCmd{ |
| 259 | + GlobalFlags: &flags.GlobalFlags{ |
| 260 | + NoWarn: true, |
| 261 | + Namespace: ns, |
| 262 | + }, |
| 263 | + Pipeline: "dot-slash-exclude", |
| 264 | + Ctx: cancelCtx, |
| 265 | + Log: log, |
| 266 | + } |
| 267 | + err := devCmd.RunDefault(f) |
| 268 | + if err != nil { |
| 269 | + f.GetLog().Errorf("error: %v", err) |
| 270 | + } |
| 271 | + done <- err |
| 272 | + }() |
| 273 | + |
| 274 | + gomega.Eventually(func(g gomega.Gomega) { |
| 275 | + g.Expect(output.String()).Should(gomega.ContainSubstring("Start watching")) |
| 276 | + }). |
| 277 | + WithTimeout(5 * time.Second). |
| 278 | + Should(gomega.Succeed()) |
| 279 | + |
| 280 | + err = os.WriteFile("foo1/test.txt", []byte("abc.txt"), 0777) |
| 281 | + framework.ExpectNoError(err) |
| 282 | + |
| 283 | + gomega.Eventually(func(g gomega.Gomega) { |
| 284 | + g.Expect(output.String()).Should(gomega.ContainSubstring("Restarting command because 'foo1/test.txt' has changed")) |
| 285 | + }). |
| 286 | + WithTimeout(5 * time.Second). |
| 287 | + Should(gomega.Succeed()) |
| 288 | + |
| 289 | + err = os.WriteFile("foo2/test.txt", []byte("abc.txt"), 0777) |
| 290 | + framework.ExpectNoError(err) |
| 291 | + |
| 292 | + gomega.Consistently(func(g gomega.Gomega) { |
| 293 | + g.Expect(output.String()).ShouldNot(gomega.ContainSubstring("Restarting command because 'foo2/test.txt' has changed")) |
| 294 | + }). |
| 295 | + WithTimeout(5 * time.Second). |
| 296 | + Should(gomega.Succeed()) |
| 297 | + |
| 298 | + cancel() |
| 299 | + err = <-done |
| 300 | + if err != nil && err != context.Canceled { |
| 301 | + framework.ExpectNoError(err) |
| 302 | + } |
| 303 | + }) |
| 304 | + |
169 | 305 | ginkgo.It("should use --set and --set-string values from run_pipelines command", func() { |
170 | 306 | tempDir, err := framework.CopyToTempDir("tests/pipelines/testdata/run_pipelines") |
171 | 307 | framework.ExpectNoError(err) |
|
0 commit comments