Skip to content

Commit e57fc47

Browse files
committed
Automatically replaces duplicate containers.
Allows customisation of mock listen port.
1 parent 2fe030a commit e57fc47

5 files changed

Lines changed: 53 additions & 10 deletions

File tree

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ Available Commands:
4242
validate Validate a file against the OpenDeps schema
4343
```
4444

45-
Create and start mocks:
45+
#### Create and start mocks
46+
47+
Example:
48+
49+
opendeps mock
50+
51+
Usage:
4652

4753
```
4854
Starts a live mock of your API dependencies, based
@@ -53,9 +59,19 @@ by this tool.
5359
5460
Usage:
5561
opendeps mock OPENDEPS_FILE
62+
63+
Flags:
64+
-p, --port Port on which to listen (default 8080)
5665
```
5766

58-
Test dependencies are available:
67+
#### Test dependencies are available
68+
69+
Example:
70+
71+
opendeps test
72+
73+
Usage:
74+
5975
```
6076
Invokes the availability endpoints of each dependency,
6177
optionally ignoring failures if the dependency is not
@@ -72,7 +88,13 @@ Flags:
7288
-s, --server stringToString Override server base URL for a dependency (e.g. foo_service=https://example.com) (default [])
7389
```
7490

75-
Create an OpenDeps manifest based on OpenAPI files:
91+
#### Create an OpenDeps manifest from OpenAPI files
92+
93+
Example:
94+
95+
opendeps scaffold
96+
97+
Usage:
7698

7799
```
78100
Creates an OpenDeps manifest based on the OpenAPI specification files in a directory.
@@ -87,7 +109,13 @@ Flags:
87109
-h, --help help for scaffold
88110
```
89111

90-
Validate OpenDeps file:
112+
#### Validate OpenDeps file
113+
114+
Example:
115+
116+
opendeps validate
117+
118+
Usage:
91119

92120
```
93121
Validates a YAML manifest file against the OpenDeps schema.
@@ -96,7 +124,7 @@ Usage:
96124
opendeps validate OPENDEPS_FILE
97125
```
98126

99-
Help:
127+
#### Help
100128

101129
```
102130
Provides help for any command in the application.

cmd/mock.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cmd
1818

1919
import (
20+
"fmt"
2021
"gatehill.io/imposter/engine"
2122
"gatehill.io/imposter/engine/docker"
2223
"github.com/sirupsen/logrus"
@@ -32,6 +33,8 @@ import (
3233
"syscall"
3334
)
3435

36+
var flagPort int
37+
3538
// mockCmd represents the mock command
3639
var mockCmd = &cobra.Command{
3740
Use: "mock OPENDEPS_FILE",
@@ -58,11 +61,12 @@ by this tool.`,
5861
openapi.BundleSpecs(stagingDir, manifestPath, manifest, flagForceOverwrite)
5962

6063
mockEngine := docker.BuildEngine(stagingDir, engine.StartOptions{
61-
Port: 8080,
64+
Port: flagPort,
6265
Version: "latest",
6366
PullPolicy: engine.PullIfNotPresent,
6467
LogLevel: "DEBUG",
6568
ReplaceRunning: true,
69+
Deduplicate: genDeduplicationKey(manifestPath, flagPort),
6670
})
6771
wg := &sync.WaitGroup{}
6872
mockEngine.Start(wg)
@@ -72,7 +76,14 @@ by this tool.`,
7276
},
7377
}
7478

79+
// genDeduplicationKey overrides the default deduplication key to a
80+
// stable value, since the staging dir is dynamic
81+
func genDeduplicationKey(manifestPath string, port int) string {
82+
return fmt.Sprintf("%v:%d", manifestPath, port)
83+
}
84+
7585
func init() {
86+
mockCmd.Flags().IntVarP(&flagPort, "port", "p", 8080, "Port on which to listen")
7687
rootCmd.AddCommand(mockCmd)
7788
}
7889

docs/install.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ curl -L https://raw.githubusercontent.com/opendeps/cli/main/install/install_open
2525
2626
See [Releases](https://github.com/opendeps/cli/releases) for the latest version.
2727

28+
---
29+
30+
# Advanced installation steps
31+
2832
## macOS
2933

3034
Only Intel x86_64 is supported on macOS.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module opendeps.org/opendeps
22

33
go 1.17
44

5-
replace gatehill.io/imposter => github.com/gatehill/imposter-cli v0.6.7
5+
replace gatehill.io/imposter => github.com/gatehill/imposter-cli v0.6.9
66

77
require (
8-
gatehill.io/imposter v0.6.7
8+
gatehill.io/imposter v0.6.9
99
github.com/fsnotify/fsnotify v1.5.1 // indirect
1010
github.com/hashicorp/hcl v1.0.0 // indirect
1111
github.com/inconshreveable/mousetrap v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWp
279279
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
280280
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
281281
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
282-
github.com/gatehill/imposter-cli v0.6.7 h1:zdJupU6tdRrpQAFATRBLRjj8JnGs3FbYFDSronqZDsM=
283-
github.com/gatehill/imposter-cli v0.6.7/go.mod h1:xSgU6ap03w66qq8EnP//1OpX8GUZwJr9tmW+X7yHZfw=
282+
github.com/gatehill/imposter-cli v0.6.9 h1:ZWBFxRJTd8k1cZtoxS7q1sJKKVst8F/RoNTY1He/VJU=
283+
github.com/gatehill/imposter-cli v0.6.9/go.mod h1:xSgU6ap03w66qq8EnP//1OpX8GUZwJr9tmW+X7yHZfw=
284284
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
285285
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
286286
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=

0 commit comments

Comments
 (0)