Skip to content

Commit

Permalink
Add docs for Gin usage + record requests/responses [TT-1842] (#1345)
Browse files Browse the repository at this point in the history
mockserver recording, update docs, move DB config
  • Loading branch information
skudasov authored Nov 17, 2024
1 parent 9da2004 commit 5887e37
Show file tree
Hide file tree
Showing 40 changed files with 441 additions and 255 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/framework-golden-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
go-modules-${{ runner.os }}
- name: Install dependencies
run: go mod download
- name: Run Docker Component Tests
- name: Run System Tests
if: steps.changes.outputs.src == 'true'
env:
CTF_CONFIGS: ${{ matrix.test.config }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-framework
cancel-in-progress: true
jobs:
test:
framework-component-tests:
defaults:
run:
working-directory: framework
Expand Down Expand Up @@ -51,4 +51,4 @@ jobs:
- name: Run Docker Component Tests
if: steps.changes.outputs.src == 'true'
run: |
go test -timeout 5m -v -count 1 -run TestDocker ./...
go test -timeout 2m -v -count 1 -run TestComponent ./...
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [Exposing Components](framework/components/state.md)
- [Components Cleanup](framework/components/cleanup.md)
- [Components Caching](framework/components/caching.md)
- [Mocking Services](framework/components/mocking.md)
- [External Environment](framework/components/external.md)
- [Secrets]()
- [Observability Stack](framework/observability/observability_stack.md)
Expand Down
7 changes: 2 additions & 5 deletions book/src/framework/components/chainlink/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ Here we provide full configuration reference, if you want to copy and run it, pl
## Configuration
```toml
[cl_node]
# Optional URL for fake data provider URL
# usually set up in test with local mock server
data_provider_url = "http://example.com"

[cl_node.db]
# PostgreSQL image version and tag
image = "postgres:15.6"
# Pulls the image every time if set to 'true', used like that in CI. Can be set to 'false' to speed up local runs
pull_image = true
pull_image = false

[cl_node.node]
# custom ports that plugins may need to expose and map to the host machine
Expand All @@ -36,7 +33,7 @@ Here we provide full configuration reference, if you want to copy and run it, pl
# Optional name for image we build, default is "ctftmp"
docker_image_name = "ctftmp"
# Pulls the image every time if set to 'true', used like that in CI. Can be set to 'false' to speed up local runs
pull_image = true
pull_image = false
# Overrides Chainlink node TOML configuration
# can be multiline, see example
user_config_overrides = """
Expand Down
28 changes: 10 additions & 18 deletions book/src/framework/components/chainlink/nodeset.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,16 @@ Then configure NodeSet
http_port_range_start = 10000
# P2P API port range start, each new node get port incremented (host machine)
p2p_port_range_start = 12000


[nodeset.db]
# PostgreSQL image version and tag
image = "postgres:15.6"
# Pulls the image every time if set to 'true', used like that in CI. Can be set to 'false' to speed up local runs
pull_image = false
# PostgreSQL volume name
volume_name = ""

[[nodeset.node_specs]]
# Optional URL for fake data provider URL
# usually set up in test with local mock server
data_provider_url = "http://example.com"

[nodeset.node_specs.db]
# PostgreSQL image version and tag
image = "postgres:15.6"
# Pulls the image every time if set to 'true', used like that in CI. Can be set to 'false' to speed up local runs
pull_image = true
# PostgreSQL volume name
volume_name = ""

[nodeset.node_specs.node]
# custom ports that plugins may need to expose and map to the host machine
Expand All @@ -83,7 +79,7 @@ Then configure NodeSet
# Optional name for image we build, default is "ctftmp"
docker_image_name = "ctftmp"
# Pulls the image every time if set to 'true', used like that in CI. Can be set to 'false' to speed up local runs
pull_image = true
pull_image = false
# Overrides Chainlink node TOML configuration
# can be multiline, see example
user_config_overrides = """
Expand Down Expand Up @@ -136,15 +132,13 @@ package capabilities_test
import (
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
"github.com/stretchr/testify/require"
"testing"
)

type Config struct {
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
}

Expand All @@ -154,9 +148,7 @@ func TestMe(t *testing.T) {

bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
require.NoError(t, err)
dp, err := fake.NewFakeDataProvider(in.MockerDataProvider)
require.NoError(t, err)
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc)
require.NoError(t, err)

t.Run("test something", func(t *testing.T) {
Expand Down
15 changes: 1 addition & 14 deletions book/src/framework/components/external.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,10 @@ For example, to integrate with remote `k8s` environment you can use `CTF_CONFIGS
http_url = "http://127.0.0.1:8545"
ws_url = "ws://127.0.0.1:8545"

[contracts]

[contracts.out]
# set up your contracts
addresses = ["0x5fbdb2315678afecb367f032d93f642f64180aa3"]
use_cache = true

[data_provider]
port = 9111

[data_provider.out]
# setup your data provider URLs
base_url_host = "http://localhost:9111"

[nodeset]

[[nodeset.node_specs]]
...

[nodeset.out]
use_cache = true
Expand Down
14 changes: 14 additions & 0 deletions book/src/framework/components/mocking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Mocking Services

The framework aims to equip you with all the necessary tools to write end-to-end system-level tests, while still allowing the flexibility to mock third-party services that are not critical to your testing scope.

## Configuration
```toml
[fake]
# port to start Gin server
port = 9111
```

## Usage

See [full](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/fake_test.go) example.
8 changes: 3 additions & 5 deletions book/src/framework/components/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ You can also define a custom set of ports for any node
[nodeset]
nodes = 5
override_mode = "each"

[nodeset.db]
image = "postgres:15.6"

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
# here we defined 2 new ports to listen and mapped them to our host machine
custom_ports = [14000, 14001]
image = "public.ecr.aws/chainlink/chainlink:v2.16.0"
pull_image = false
```
3 changes: 0 additions & 3 deletions book/src/framework/connecting_chainlink_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ Create your configuration in `smoke.toml`
type = "anvil"

[cl_node]
data_provider_url = "http://example.com"

[cl_node.db]
image = "postgres:15.6"
pull_image = true

[cl_node.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true
```

Create your test in `smoke_test.go`
Expand Down
12 changes: 3 additions & 9 deletions book/src/framework/nodeset_capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,21 @@ Create a configuration file `smoke.toml`
port = "8545"
type = "anvil"

[data_provider]
port = 9111

[nodeset]
nodes = 5
override_mode = "all"

[nodeset.db]
image = "postgres:15.6"

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
# path to your capability binaries
capabilities = ["./kvstore"]
# default capabilities directory
# capabilities_container_dir = "/home/capabilities"
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true

```

Run it
Expand Down
31 changes: 3 additions & 28 deletions book/src/framework/nodeset_compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,45 @@ Create a configuration file `smoke.toml`
port = "8545"
type = "anvil"

[data_provider]
port = 9111

[nodeset]
nodes = 5
override_mode = "each"

[[nodeset.node_specs]]
[nodeset.db]
image = "postgres:15.6"

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true
[[nodeset.node_specs]]

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true
user_config_overrides = " [Log]\n level = 'info'\n "
user_secrets_overrides = ""

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true
user_config_overrides = " [Log]\n level = 'info'\n "
user_secrets_overrides = ""

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true
user_config_overrides = " [Log]\n level = 'info'\n "
user_secrets_overrides = ""

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true
user_config_overrides = " [Log]\n level = 'info'\n "
user_secrets_overrides = ""

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true
user_config_overrides = " [Log]\n level = 'info'\n "
user_secrets_overrides = ""
```
Expand Down
11 changes: 3 additions & 8 deletions book/src/framework/nodeset_docker_rebuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,18 @@ Create a configuration file `smoke.toml`
port = "8545"
type = "anvil"

[data_provider]
port = 9111

[nodeset]
nodes = 5
override_mode = "all"

[nodeset.db]
image = "postgres:15.6"

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
docker_file = "../../core/chainlink.Dockerfile"
docker_ctx = "../.."
pull_image = true
```

These paths will work for `e2e/capabilities` in our main [repository](https://github.com/smartcontractkit/chainlink/tree/ctf-v2-tests/e2e/capabilities)
Expand Down
17 changes: 4 additions & 13 deletions book/src/framework/nodeset_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ Create a configuration file `smoke.toml`
port = "8545"
type = "anvil"

[data_provider]
port = 9111

[nodeset]
nodes = 5
override_mode = "all"

[nodeset.db]
image = "postgres:15.6"

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = true
```

Create a file `smoke_test.go`
Expand All @@ -35,15 +30,13 @@ package yourpackage_test
import (
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
"github.com/stretchr/testify/require"
"testing"
)

type Config struct {
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
}

Expand All @@ -53,9 +46,7 @@ func TestNodeSet(t *testing.T) {

bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
require.NoError(t, err)
dp, err := fake.NewFakeDataProvider(in.MockerDataProvider)
require.NoError(t, err)
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc)
require.NoError(t, err)

t.Run("test something", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 5887e37

Please sign in to comment.