|
| 1 | +package render |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "strings" |
| 8 | + "sync" |
| 9 | + |
| 10 | + "github.com/loft-sh/devspace/cmd" |
| 11 | + "github.com/loft-sh/devspace/cmd/flags" |
| 12 | + "github.com/loft-sh/devspace/e2e/framework" |
| 13 | + "github.com/loft-sh/devspace/pkg/util/factory" |
| 14 | + "github.com/onsi/ginkgo" |
| 15 | +) |
| 16 | + |
| 17 | +var _ = DevSpaceDescribe("build", func() { |
| 18 | + |
| 19 | + initialDir, err := os.Getwd() |
| 20 | + if err != nil { |
| 21 | + panic(err) |
| 22 | + } |
| 23 | + |
| 24 | + // create a new factory |
| 25 | + var f factory.Factory |
| 26 | + |
| 27 | + ginkgo.BeforeEach(func() { |
| 28 | + f = framework.NewDefaultFactory() |
| 29 | + }) |
| 30 | + |
| 31 | + // Test cases: |
| 32 | + |
| 33 | + ginkgo.It("should render helm charts", func() { |
| 34 | + tempDir, err := framework.CopyToTempDir("tests/render/testdata/helm") |
| 35 | + framework.ExpectNoError(err) |
| 36 | + defer framework.CleanupTempDir(initialDir, tempDir) |
| 37 | + |
| 38 | + stdout := &Buffer{} |
| 39 | + // create build command |
| 40 | + renderCmd := &cmd.RenderCmd{ |
| 41 | + GlobalFlags: &flags.GlobalFlags{ |
| 42 | + NoWarn: true, |
| 43 | + }, |
| 44 | + SkipPush: true, |
| 45 | + Writer: stdout, |
| 46 | + } |
| 47 | + err = renderCmd.Run(f) |
| 48 | + framework.ExpectNoError(err) |
| 49 | + content := strings.TrimSpace(stdout.String()) + "\n" |
| 50 | + framework.ExpectLocalFileContentsImmediately(filepath.Join(tempDir, "rendered.txt"), content) |
| 51 | + }) |
| 52 | + |
| 53 | + ginkgo.It("should render kubectl deployments", func() { |
| 54 | + tempDir, err := framework.CopyToTempDir("tests/render/testdata/kubectl") |
| 55 | + framework.ExpectNoError(err) |
| 56 | + defer framework.CleanupTempDir(initialDir, tempDir) |
| 57 | + |
| 58 | + stdout := &Buffer{} |
| 59 | + // create build command |
| 60 | + renderCmd := &cmd.RenderCmd{ |
| 61 | + GlobalFlags: &flags.GlobalFlags{ |
| 62 | + NoWarn: true, |
| 63 | + }, |
| 64 | + SkipPush: true, |
| 65 | + Writer: stdout, |
| 66 | + } |
| 67 | + err = renderCmd.Run(f) |
| 68 | + framework.ExpectNoError(err) |
| 69 | + content := strings.TrimSpace(stdout.String()) + "\n" |
| 70 | + framework.ExpectLocalFileContentsImmediately(filepath.Join(tempDir, "rendered.txt"), content) |
| 71 | + }) |
| 72 | +}) |
| 73 | + |
| 74 | +// Buffer is a goroutine safe bytes.Buffer |
| 75 | +type Buffer struct { |
| 76 | + buffer bytes.Buffer |
| 77 | + mutex sync.Mutex |
| 78 | +} |
| 79 | + |
| 80 | +// Write appends the contents of p to the buffer, growing the buffer as needed. It returns |
| 81 | +// the number of bytes written. |
| 82 | +func (s *Buffer) Write(p []byte) (n int, err error) { |
| 83 | + s.mutex.Lock() |
| 84 | + defer s.mutex.Unlock() |
| 85 | + return s.buffer.Write(p) |
| 86 | +} |
| 87 | + |
| 88 | +// String returns the contents of the unread portion of the buffer |
| 89 | +// as a string. If the Buffer is a nil pointer, it returns "<nil>". |
| 90 | +func (s *Buffer) String() string { |
| 91 | + s.mutex.Lock() |
| 92 | + defer s.mutex.Unlock() |
| 93 | + return s.buffer.String() |
| 94 | +} |
0 commit comments