-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
57 lines (47 loc) · 1.88 KB
/
integration_test.go
File metadata and controls
57 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"os"
"os/exec"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
// TestCLIGenerationWorkflow tests the complete CLI workflow
func TestCLIGenerationWorkflow(t *testing.T) {
// Build the binary in a temporary directory
testDir := t.TempDir()
binaryPath := filepath.Join(testDir, "cozyvalues-gen-test")
buildCmd := exec.Command("go", "build", "-o", binaryPath)
buildCmd.Dir = "."
output, err := buildCmd.CombinedOutput()
require.NoError(t, err, "failed to build: %s", string(output))
// Test on each example
examples := []string{"monitoring.yaml", "postgres.yaml", "virtual-machine.yaml"}
for _, example := range examples {
t.Run(example, func(t *testing.T) {
examplePath := filepath.Join("examples", example)
tmpDir := t.TempDir()
goOut := filepath.Join(tmpDir, "types.go")
schemaOut := filepath.Join(tmpDir, "values.schema.json")
cmd := exec.Command(
binaryPath,
"-v", examplePath,
"-g", goOut,
"-s", schemaOut,
)
output, err := cmd.CombinedOutput()
require.NoError(t, err, "generator failed for %s: %s", example, string(output))
// Verify outputs exist and are not empty
goData, err := os.ReadFile(goOut)
require.NoError(t, err, "failed to read generated Go file")
require.NotEmpty(t, goData, "generated Go file should not be empty")
require.Contains(t, string(goData), "package values", "should contain package declaration")
require.Contains(t, string(goData), "type Config struct", "should contain Config type")
schemaData, err := os.ReadFile(schemaOut)
require.NoError(t, err, "failed to read generated schema file")
require.NotEmpty(t, schemaData, "generated schema should not be empty")
require.Contains(t, string(schemaData), `"title": "Chart Values"`, "schema should have title")
require.Contains(t, string(schemaData), `"properties"`, "schema should have properties")
})
}
}