Skip to content

Commit c423243

Browse files
committed
all product-agnostic boilerplate
1 parent 46f6bcc commit c423243

File tree

5 files changed

+1576
-575
lines changed

5 files changed

+1576
-575
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
- [Framework](./framework/overview.md)
55
- [Basic Usage](./framework/getting_started.md)
66
- [Getting Started](./framework/getting_started.md)
7-
- [Your First Test](./framework/first_test.md)
8-
- [NodeSet Environment](./framework/nodeset_environment.md)
9-
- [NodeSet (Capabilities)](./framework/nodeset_capabilities.md)
10-
- [NodeSet (Local Docker builds)](./framework/nodeset_docker_rebuild.md)
7+
- [Generating Developer Environment](./framework/generate.md)
118
- [Advanced Usage](./framework/configuration.md)
129
- [CLI](./framework/cli.md)
1310
- [Configuration](./framework/configuration.md)
1411
- [Debugging Tests](framework/components/debug.md)
15-
- [Generating Tests](framework/generate.md)
1612
- [Creating your own components](./developing/developing_components.md)
1713
- [Exposing Components](framework/components/state.md)
1814
- [Asserting Logs](./developing/asserting_logs.md)

book/src/framework/generate.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
# Generating Tests
1+
# Generating Chainlink Environment
22

3-
Some types of tests may require a lot of boilerplate and configurability, for example load and chaos tests.
3+
Our code generation tools automatically build complete Chainlink environments and test templates, which minimizes documentation and provides a framework that is both structured and easily extensible.
44

5-
We provide code generation tool that help you to start with best practes in such cases.
5+
Let's read `help` first and then build an environment for a single EVM network:
6+
```bash
7+
ctf gen -h
8+
# generate a new Chainlink environment in "devenv" directory with 4 Chainlink nodes and one EVM network. Generate CLI called "pcli" and enter the shell
9+
ctf gen env --cli pcli --product-name MyProduct --output-dir devenv --nodes 4
10+
```
611

7-
All generators have `-h` or `--help` flag, please read the docs!
12+
Follow further instructions in `devenv/README.md`
13+
14+
# Generating Infrastructure Testing Template
15+
16+
If you have Chainlink infrastructure already deployed it's useful to generate a workload + chaos suite template.
17+
```bash
18+
ctf gen load -h
19+
# generate test suite named ChaosGen, with workload + default chaos experiments (fail + latency) for all the pods that have app.kubernetes.io/instance annotation
20+
ctf gen load -w -n ChaosGen default
21+
```

framework/cmd/main.go

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"os/exec"
78
"path/filepath"
89
"strings"
910

@@ -32,25 +33,16 @@ func main() {
3233
Description: `🔗 Chainlink's Developer Environment Generator 🔗
3334
3435
Prerequisites:
35-
We are using Just, please install it first - https://github.com/casey/just
36+
We are using Just, please install it first - https://github.com/casey/just
3637
3738
Usage:
3839
3940
⚙️ Generate basic environment:
40-
ctf gen env --cli myenv --product-name Knilniahc --nodes 4
41+
ctf gen env --cli myenv --output-dir devenv --product-name Knilniahc --nodes 4
42+
43+
📜 Read the docs in devenv/README.md
4144
42-
🔧 Address all TODO comments and customize it if needed
43-
44-
💻 Enter the shell and spin up the environment:
45-
cd devenv && just cli && myenv sh
46-
47-
🔍 Implement system-level smoke tests (tests/smoke_test.go) and run them:
48-
myenv test smoke
49-
50-
📈 Implement load/chaos tests (tests/load_test.go) and run them:
51-
myenv test load
52-
53-
🔄 Enforce quality standards in CI: copy .github/workflows to your CI folder and commit
45+
🔧 Address all TODO comments and customize it
5446
`,
5547
ArgsUsage: "",
5648
Flags: []cli.Flag{
@@ -59,6 +51,12 @@ Usage:
5951
Aliases: []string{"c"},
6052
Usage: "Your devenv CLI binary name",
6153
},
54+
&cli.StringFlag{
55+
Name: "output-dir",
56+
Aliases: []string{"o"},
57+
Value: "devenv",
58+
Usage: "Your devenv directory",
59+
},
6260
&cli.StringFlag{
6361
Name: "product-name",
6462
Aliases: []string{"r"},
@@ -78,6 +76,7 @@ Usage:
7876
},
7977
},
8078
Action: func(c *cli.Context) error {
79+
outputDir := c.String("output-dir")
8180
productConfType := c.String("product-configuration-type")
8281
nodes := c.Int("nodes")
8382
cliName := c.String("cli")
@@ -89,18 +88,47 @@ Usage:
8988
return fmt.Errorf("Product name must be specified, call your product somehow, any name")
9089
}
9190
framework.L.Info().
91+
Str("OutputDir", outputDir).
9292
Str("Name", cliName).
9393
Int("CLNodes", nodes).
9494
Str("ProductConfigurationType", productConfType).
9595
Msg("Generating developer environment")
9696

97-
cg, err := framework.NewEnvBuilder(cliName, nodes, productConfType, productName).Build()
97+
cg, err := framework.NewEnvBuilder(cliName, nodes, productConfType, productName).
98+
OutputDir(outputDir).
99+
Build()
98100
if err != nil {
99101
return fmt.Errorf("failed to create codegen: %w", err)
100102
}
101103
if err := cg.Write(); err != nil {
102104
return fmt.Errorf("failed to generate module: %w", err)
103105
}
106+
107+
fmt.Println()
108+
fmt.Printf("📁 Your environment directory is: %s\n", outputDir)
109+
fmt.Printf("💻 Your CLI name is: %s\n", cliName)
110+
fmt.Printf("📜 More docs can be found in %s/README.md\n", outputDir)
111+
fmt.Println()
112+
113+
cmd := exec.Command("just", "cli")
114+
cmd.Env = os.Environ()
115+
cmd.Dir = outputDir
116+
out, err := cmd.CombinedOutput()
117+
if err != nil {
118+
return fmt.Errorf("failed to build CLI via Justfile: %w, output: %s", err, string(out))
119+
}
120+
if err := os.Chdir(outputDir); err != nil {
121+
return err
122+
}
123+
cmd = exec.Command(cliName, "sh")
124+
cmd.Env = os.Environ()
125+
cmd.Stdin = os.Stdin
126+
cmd.Stdout = os.Stdout
127+
cmd.Stderr = os.Stderr
128+
err = cmd.Run()
129+
if err != nil {
130+
return fmt.Errorf("failed to enter devenv shell: %w", err)
131+
}
104132
return nil
105133
},
106134
},

0 commit comments

Comments
 (0)