-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_executor_test.go
More file actions
79 lines (68 loc) · 2.03 KB
/
Copy pathnode_executor_test.go
File metadata and controls
79 lines (68 loc) · 2.03 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
package executors
import (
"context"
"os"
"testing"
"github.com/spf13/afero"
"github.com/terraconstructs/go-synth/models"
)
func Test_nodeExecutor_Setup(t *testing.T) {
be := getTestNodeExecutor()
defer be.Cleanup(context.Background())
envVars := EnvMap(os.Environ())
err := be.Setup(context.Background(), models.AppConfig{}, envVars)
if err != nil {
t.Fatalf("Setup failed: %v", err)
}
snapshotFs(t, "node_setup", ".", be.fs)
}
func Test_nodeExecutor_Fixtures(t *testing.T) {
ctx := context.Background()
be := getTestNodeExecutor()
defer be.Cleanup(ctx)
be.logger.Info(be.workingDir)
envVars := EnvMap(os.Environ())
fixtureFs := afero.NewBasePathFs(afero.NewOsFs(), "../fixtures")
// copy in local package
if err := be.CopyFrom(ctx, fixtureFs, "cdktf-lib", "./fixtures/cdktf-lib", models.CopyOptions{
SkipDirs: []string{"node_modules"},
}); err != nil {
t.Fatalf("CopyFrom failed: %v", err)
}
// copy in local file
if err := be.CopyFileFrom(ctx, fixtureFs, "testfile", "testfile"); err != nil {
t.Fatalf("CopyFileFrom failed: %v", err)
}
err := be.Setup(ctx, models.AppConfig{
Dependencies: map[string]string{
"cdktf-lib": "./fixtures/cdktf-lib",
},
ExecutorOptions: map[string]string{
// required for pnpm to install cdktf-lib dependencies ...
"pnpmWorkspace": "packages:\n- \"./fixtures/cdktf-lib\"",
},
}, envVars)
if err != nil {
t.Fatalf("Setup failed: %v", err)
}
var mainTs []byte
if mainTs, err = afero.ReadFile(fixtureFs, "local-package/main.ts"); err != nil {
t.Fatalf("ReadAll failed: %v", err)
}
if err := be.Exec(ctx, string(mainTs), envVars); err != nil {
t.Fatalf("Exec failed: %v", err)
}
// assert the testfile exists in the be.fs
exists, err := afero.Exists(be.fs, "testfile")
if err != nil {
t.Fatalf("Failed to check if testfile exists: %v", err)
}
if !exists {
t.Errorf("testfile was not created")
}
snapshotFs(t, "node_fixtures", "cdktf.out", be.fs)
}
func getTestNodeExecutor() *nodeExecutor {
be, _ := NewNodeExecutor(getPrettyLogger())
return be.(*nodeExecutor)
}