-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathrun.go
More file actions
94 lines (78 loc) · 2.31 KB
/
Copy pathrun.go
File metadata and controls
94 lines (78 loc) · 2.31 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"dagger.io/dagger"
"github.com/open-feature/cli/test/integration"
)
// Test implements the integration test for the Go generator
type Test struct {
// projectDir is the absolute path to the root of the project
projectDir string
// TestDir is the absolute path to the test directory
TestDir string
}
// New creates a new Test
func New(projectDir, testDir string) *Test {
return &Test{
projectDir: projectDir,
TestDir: testDir,
}
}
// Run executes the Go integration test using Dagger
func (t *Test) Run(ctx context.Context, client *dagger.Client, cli *dagger.Container) (*dagger.Container, error) {
// Test source files
testFiles := client.Host().Directory(t.TestDir, dagger.HostDirectoryOpts{
Include: []string{"test.go", "go.mod"},
})
// Generate Go client using the pre-built CLI
generated := cli.WithExec([]string{
"./cli", "generate", "go",
"--manifest=/src/sample/sample_manifest.json",
"--output=/tmp/generated",
"--package-name=openfeature",
})
// Get generated files
generatedFiles := generated.Directory("/tmp/generated")
// Test Go compilation with the generated files
goContainer := client.Container().
From(integration.GoGenerateMinCompatImage).
WithWorkdir("/app").
WithDirectory("/app", testFiles).
WithDirectory("/app/openfeature", generatedFiles).
WithExec([]string{"go", "mod", "tidy"}).
WithExec([]string{"go", "build", "-o", "test", "-v"}).
WithExec([]string{"./test"})
return goContainer, nil
}
// Name returns the name of the integration test
func (t *Test) Name() string {
return "go"
}
// ProjectDir returns the absolute path to the project root
func (t *Test) ProjectDir() string {
return t.projectDir
}
func main() {
ctx := context.Background()
// Get project root
projectDir, err := filepath.Abs(os.Getenv("PWD"))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get project dir: %v\n", err)
os.Exit(1)
}
// Get test directory
testDir, err := filepath.Abs(filepath.Join(projectDir, "test/go-integration"))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get test dir: %v\n", err)
os.Exit(1)
}
// Create and run the Go integration test
test := New(projectDir, testDir)
if err := integration.RunTest(ctx, test); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}