Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions e2e/framework/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package framework
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -95,3 +96,18 @@ func (f *Framework) ExecCommandCapture(ctx context.Context, args []string) (stri
err := cmd.Run()
return execOut.String(), execErr.String(), err
}

// ExecCommandJSON runs the devsy test binary and decodes its stdout as a JSON object.
func (f *Framework) ExecCommandJSON(ctx context.Context, args []string) (map[string]any, error) {
stdout, stderr, err := f.ExecCommandCapture(ctx, args)
if err != nil {
return nil, fmt.Errorf("devsy %s: %w (stderr: %s)", strings.Join(args, " "), err, stderr)
}

var result map[string]any
if err := json.Unmarshal([]byte(stdout), &result); err != nil {
return nil, fmt.Errorf("output should be valid JSON: %w", err)
}

return result, nil
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
72 changes: 12 additions & 60 deletions e2e/tests/configread/configread.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err, "output should be valid JSON")

gomega.Expect(result).To(gomega.HaveKey("configuration"))
gomega.Expect(result).To(gomega.HaveKey("workspace"))

Expand Down Expand Up @@ -68,17 +64,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
"--include-features-configuration",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err)

gomega.Expect(result).To(gomega.HaveKey("features"))
features, ok := result["features"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue(), "features should be an object")
Expand All @@ -92,17 +84,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
"--include-merged-configuration",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err)

gomega.Expect(result).To(gomega.HaveKey("mergedConfiguration"))
merged, ok := result["mergedConfiguration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue(), "mergedConfiguration should be an object")
Expand Down Expand Up @@ -138,17 +126,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata-port-range")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
"--include-merged-configuration",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err)

merged, ok := result["mergedConfiguration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue())

Expand Down Expand Up @@ -176,17 +160,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata-port-attributes")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
"--include-merged-configuration",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err)

merged, ok := result["mergedConfiguration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue())

Expand All @@ -212,16 +192,12 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata-container-env")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err, "output should be valid JSON")

config, ok := result["configuration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue(), "configuration should be an object")

Expand All @@ -235,17 +211,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata-container-env")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
"--include-merged-configuration",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err)

merged, ok := result["mergedConfiguration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue(), "mergedConfiguration should be an object")

Expand All @@ -259,16 +231,12 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir("tests/configread/testdata-host-requirements")

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err, "output should be valid JSON")

config, ok := result["configuration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue(), "configuration should be an object")

Expand All @@ -291,17 +259,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
"--id-label", "devsy.readconfig.test=custom")
framework.ExpectNoError(err)

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--id-label", "devsy.readconfig.test=custom",
"--include-merged-configuration",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err, "output should be valid JSON")

gomega.Expect(result).To(gomega.HaveKey("configuration"))
gomega.Expect(result).To(gomega.HaveKey("mergedConfiguration"))

Expand All @@ -328,16 +292,12 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
_ = cmd.Run()
})

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--container-id", containerID,
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err, "output should be valid JSON")

gomega.Expect(result).To(gomega.HaveKey("configuration"))
gomega.Expect(result).To(gomega.HaveKey("workspace"))

Expand Down Expand Up @@ -414,17 +374,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
_ = cmd.Run()
})

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--container-id", containerID,
"--docker-path", "docker",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err, "output should be valid JSON")

config, ok := result["configuration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue())
gomega.Expect(config).To(
Expand All @@ -450,17 +406,13 @@ var _ = ginkgo.Describe("config read command", ginkgo.Label("config-read"), func
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir := framework.CopyTestdataNoChdir(testdataDir)

stdout, _, err := f.ExecCommandCapture(ctx, []string{
result, err := f.ExecCommandJSON(ctx, []string{
cmdConfig, cmdRead,
"--workspace-folder", tempDir,
"--include-merged-configuration",
})
framework.ExpectNoError(err)

var result map[string]any
err = json.Unmarshal([]byte(stdout), &result)
framework.ExpectNoError(err)

merged, ok := result["mergedConfiguration"].(map[string]any)
gomega.Expect(ok).To(gomega.BeTrue(), "mergedConfiguration should be an object")
gomega.Expect(merged).To(
Expand Down
Loading