Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Run `imposter up` to start your mock.

## Install

You'll need [Docker](https://docs.docker.com/get-docker/), or alternatively a JVM ([JVM engine](./docs/engine_jvm.md)) or no extra runtime at all ([Golang engine](./docs/engine_golang.md)).
You'll need [Docker](https://docs.docker.com/get-docker/), or alternatively a JVM ([JVM engine](./docs/engine_jvm.md)) or no extra runtime at all ([Native engine](./docs/engine_native.md)).

### Homebrew

Expand Down Expand Up @@ -127,7 +127,7 @@ Other deeper guides:

- [Docker engine](./docs/engine_docker.md) — the default
- [JVM engine](./docs/engine_jvm.md)
- [Golang engine](./docs/engine_golang.md)
- [Native engine](./docs/engine_native.md)
- [Run the CLI itself in Docker](./docs/docker.md)
- [SDK — embed Imposter in your Go app](./docs/sdk.md)
- [Upgrade](./docs/upgrade.md)
Expand Down
4 changes: 2 additions & 2 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ var localTypes = []engine.EngineType{
engine.EngineTypeDockerAll,
engine.EngineTypeDockerDistroless,
engine.EngineTypeJvmSingleJar,
engine.EngineTypeGolang,
engine.EngineTypeNative,
}

// allEngineTypes is the distinct set of engine types used by --all flags.
// Only one docker variant is included to avoid duplicate results.
var allEngineTypes = []engine.EngineType{
engine.EngineTypeDockerCore,
engine.EngineTypeJvmSingleJar,
engine.EngineTypeGolang,
engine.EngineTypeNative,
}

// runWithRecovery executes fn, recovering from logger.Fatal calls that
Expand Down
2 changes: 1 addition & 1 deletion cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var downCmd = &cobra.Command{
}

func init() {
downCmd.Flags().StringVarP(&downFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,golang,jvm - default \"docker\")")
downCmd.Flags().StringVarP(&downFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,native,jvm - default \"docker\")")
downCmd.Flags().BoolVarP(&downFlags.all, "all", "a", false, "Stop mocks for all engine types")
downCmd.MarkFlagsMutuallyExclusive("engine-type", "all")
registerEngineTypeCompletions(downCmd)
Expand Down
4 changes: 2 additions & 2 deletions cmd/down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func Test_stopEngine(t *testing.T) {
engineType: engine.EngineTypeJvmSingleJar,
},
{
name: "stop golang engine",
engineType: engine.EngineTypeGolang,
name: "stop native engine",
engineType: engine.EngineTypeNative,
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion cmd/engine_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func renderEngines(rows [][]string) {
}

func init() {
engineListCmd.Flags().StringVarP(&engineListFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,golang,jvm - default is all")
engineListCmd.Flags().StringVarP(&engineListFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,native,jvm - default is all")
registerEngineTypeCompletions(engineListCmd)
engineCmd.AddCommand(engineListCmd)
}
2 changes: 1 addition & 1 deletion cmd/engine_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func pull(version string, engineType engine.EngineType, pullPolicy engine.PullPo
}

func init() {
enginePullCmd.Flags().StringVarP(&enginePullFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,golang,jvm - default \"docker\")")
enginePullCmd.Flags().StringVarP(&enginePullFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,native,jvm - default \"docker\")")
enginePullCmd.Flags().StringVarP(&enginePullFlags.engineVersion, "version", "v", "", "Imposter engine version (default \"latest\")")
enginePullCmd.Flags().BoolVarP(&enginePullFlags.forcePull, "force", "f", false, "Force engine pull")
registerEngineTypeCompletions(enginePullCmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ and reports their health.`,
}

func init() {
listCmd.Flags().StringVarP(&listFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,golang,jvm - default \"docker\")")
listCmd.Flags().StringVarP(&listFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,native,jvm - default \"docker\")")
listCmd.Flags().BoolVarP(&listFlags.all, "all", "a", false, "List mocks for all engine types")
listCmd.Flags().BoolVarP(&listFlags.healthExitCode, "exit-code-health", "x", false, "Set exit code based on mock health")
listCmd.Flags().BoolVarP(&listFlags.quiet, "quiet", "q", false, "Quieten output; only print ID")
Expand Down
8 changes: 4 additions & 4 deletions cmd/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"bytes"
"github.com/imposter-project/imposter-cli/internal/engine"
"github.com/imposter-project/imposter-cli/internal/engine/docker"
"github.com/imposter-project/imposter-cli/internal/engine/golang"
"github.com/imposter-project/imposter-cli/internal/engine/jvm"
"github.com/imposter-project/imposter-cli/internal/engine/native"
"github.com/stretchr/testify/require"
"os"
"testing"
Expand All @@ -30,7 +30,7 @@ import (
func init() {
docker.EnableEngine()
jvm.EnableSingleJarEngine()
golang.EnableEngine()
native.EnableEngine()
}

func Test_renderMocks_without_engine(t *testing.T) {
Expand Down Expand Up @@ -124,8 +124,8 @@ func Test_listMocksForEngine(t *testing.T) {
showEngine: true,
},
{
name: "list golang mocks",
engineType: engine.EngineTypeGolang,
name: "list native mocks",
engineType: engine.EngineTypeNative,
showEngine: true,
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ var pluginCmd = &cobra.Command{
}

func init() {
pluginCmd.PersistentFlags().StringVarP(&pluginFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,golang,jvm)")
pluginCmd.PersistentFlags().StringVarP(&pluginFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,native,jvm)")
rootCmd.AddCommand(pluginCmd)
}
4 changes: 2 additions & 2 deletions cmd/plugin_uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func Test_uninstallNonInstalledPluginFromDefaults(t *testing.T) {
})

// Test uninstalling a plugin that's in defaults but not installed
uninstallPlugins([]string{"swaggerui"}, engine.EngineTypeGolang, "1.2.4", true)
uninstallPlugins([]string{"swaggerui"}, engine.EngineTypeNative, "1.2.4", true)

// Verify plugin was removed from defaults
defaultPlugins, err := plugin.ListDefaultPlugins()
Expand Down Expand Up @@ -200,7 +200,7 @@ func Test_uninstallMultiplePluginsFromDefaults(t *testing.T) {
}

// Test uninstalling some plugins that are in defaults but not installed
uninstallPlugins([]string{"swaggerui", "store-redis"}, engine.EngineTypeGolang, "1.2.4", true)
uninstallPlugins([]string{"swaggerui", "store-redis"}, engine.EngineTypeNative, "1.2.4", true)

// Verify specified plugins were removed from defaults
defaultPlugins, err := plugin.ListDefaultPlugins()
Expand Down
2 changes: 1 addition & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ If CONFIG_DIR is not specified, the current working directory is used.`,
}

func init() {
upCmd.Flags().StringVarP(&upFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,golang,jvm - default \"docker\")")
upCmd.Flags().StringVarP(&upFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,native,jvm - default \"docker\")")
upCmd.Flags().StringVarP(&upFlags.engineVersion, "version", "v", "", "Imposter engine version (default \"latest\")")
upCmd.Flags().IntVarP(&upFlags.port, "port", "p", 8080, "Port on which to listen")
upCmd.Flags().BoolVar(&upFlags.forcePull, "pull", false, "Force engine pull")
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var versionCmd = &cobra.Command{
}

func init() {
versionCmd.Flags().StringVarP(&versionFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,golang,jvm - default \"docker\")")
versionCmd.Flags().StringVarP(&versionFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,native,jvm - default \"docker\")")
versionCmd.Flags().StringVarP(&versionFlags.format, "output-format", "o", "", "Output format (valid: plain,json - default \"plain\")")
versionCmd.Flags().BoolVar(&versionFlags.full, "full", false, "Also print the engine version (if available)")
registerEngineTypeCompletions(versionCmd)
Expand Down
4 changes: 2 additions & 2 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func Test_describeVersions(t *testing.T) {
},
},
{
name: "print latest version (golang)",
name: "print latest version (native)",
args: args{
engineType: engine.EngineTypeGolang,
engineType: engine.EngineTypeNative,
version: "latest",
full: true,
format: outputFormatPlain,
Expand Down
7 changes: 4 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ You can also use a configuration file to set CLI defaults. By default, Imposter
The currently supported elements are as follows:

```yaml
# the engine type - valid values are "docker", "jvm" or "golang"
# the engine type - valid values are "docker", "jvm" or "native"
# (the legacy value "golang" is still accepted as an alias for "native")
engine: "docker"

# the engine version - valid values are "latest", or a binary release such as "2.0.1"
Expand Down Expand Up @@ -105,8 +106,8 @@ Some configuration elements can be specified as environment variables:

### Engine types

Imposter supports different mock engine types: Docker (default), JVM and Golang. For more information about configuring the engine type see:
Imposter supports different mock engine types: Docker (default), JVM and native. For more information about configuring the engine type see:

- [Docker engine](./engine_docker.md) (default)
- [JVM engine](./engine_jvm.md)
- [Golang engine](./engine_golang.md)
- [Native engine](./engine_native.md)
2 changes: 1 addition & 1 deletion docs/engine_docker.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using the Docker mock engine

Imposter supports different mock engine types: Docker, [JVM](./engine_jvm.md) and [Golang](./engine_golang.md). This document describes how to use the **Docker** engine.
Imposter supports different mock engine types: Docker, [JVM](./engine_jvm.md) and [Native](./engine_native.md). This document describes how to use the **Docker** engine.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion docs/engine_jvm.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using the JVM mock engine

Imposter supports different mock engine types: [Docker](./engine_docker.md), JVM and [Golang](./engine_golang.md). This document describes how to use the **JVM** engine.
Imposter supports different mock engine types: [Docker](./engine_docker.md), JVM and [Native](./engine_native.md). This document describes how to use the **JVM** engine.

## Prerequisites

Expand Down
22 changes: 12 additions & 10 deletions docs/engine_golang.md → docs/engine_native.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Using the Golang mock engine
# Using the native mock engine

Imposter supports different mock engine types: [Docker](./engine_docker.md), [JVM](./engine_jvm.md) and Golang. This document describes how to use the **Golang** engine.
Imposter supports different mock engine types: [Docker](./engine_docker.md), [JVM](./engine_jvm.md) and native. This document describes how to use the **native** engine.

The Golang engine is a lightweight, single-binary implementation of Imposter. It supports REST, OpenAPI, SOAP and gRPC mocking with JavaScript scripting.
The native engine is a lightweight, single-binary implementation of Imposter. It supports REST, OpenAPI, SOAP and gRPC mocking with JavaScript scripting.

> The native engine was previously named `golang`. The `golang` value is still accepted as a deprecated alias wherever the engine type can be configured.

## Prerequisites

No additional software is required. The Golang engine is downloaded automatically by the CLI.
No additional software is required. The native engine is downloaded automatically by the CLI.

## Features

The Golang engine supports:
The native engine supports:

- REST, OpenAPI (2.0 and 3.0+), SOAP (1.1 and 1.2) and gRPC plugins
- JavaScript scripting (Groovy is **not** supported)
Expand All @@ -30,29 +32,29 @@ The easiest way to set the engine type is to edit your user default [configurati

$HOME/.imposter/config.yaml

Set the `engine` key to `golang`:
Set the `engine` key to `native`:

```yaml
engine: golang
engine: native
```

### Environment variable

If you don't want to set your user defaults you can set the following environment variable:

IMPOSTER_ENGINE=golang
IMPOSTER_ENGINE=native

### Command line argument

You can also provide the `--engine-type` (or `-t`) command line argument to the `imposter up` command:

Example:

imposter up --engine-type golang
imposter up --engine-type native

Or:

imposter up -t golang
imposter up -t native

## Differences from the JVM engine

Expand Down
2 changes: 1 addition & 1 deletion docs/engine_unpacked.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> **Important:** This method is primarily intended for use by tools, not end users. If you are unsure, and you really want to use the JVM directly, you probably want the [JVM engine](./engine_jvm.md).

Imposter supports different mock engine types: [Docker](./engine_docker.md), [JVM](./engine_jvm.md) and [Golang](./engine_golang.md). This document describes how to use the **unpacked** engine.
Imposter supports different mock engine types: [Docker](./engine_docker.md), [JVM](./engine_jvm.md) and [Native](./engine_native.md). This document describes how to use the **unpacked** engine.

## Prerequisites

Expand Down
4 changes: 2 additions & 2 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Imposter can be installed on Linux, macOS and Windows.

## Prerequisites

Imposter supports different mock engine types: Docker (default), JVM and Golang. For more information about configuring the engine type see:
Imposter supports different mock engine types: Docker (default), JVM and native. For more information about configuring the engine type see:

- [Docker engine](./engine_docker.md) (default)
- [JVM engine](./engine_jvm.md)
- [Golang engine](./engine_golang.md)
- [Native engine](./engine_native.md)

**You must have at least one of the engine types configured to use Imposter.**

Expand Down
8 changes: 4 additions & 4 deletions docs/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Imposter SDK allows you to embed Imposter directly into your own Go applicat
There are a few key concepts to learn before using the SDK:

- **configuration directory**: a directory containing a valid Imposter [configuration](https://docs.imposter.sh/configuration/)
- **engine type**: this can be `docker`, `jvm` or `golang` - see [Docker Engine](./engine_docker.md), [JVM Engine](./engine_jvm.md) or [Golang Engine](./engine_golang.md)
- **engine type**: this can be `docker`, `jvm` or `native` - see [Docker Engine](./engine_docker.md), [JVM Engine](./engine_jvm.md) or [Native Engine](./engine_native.md)
- **engine version**: this is the version of Imposter - see [Releases](https://github.com/imposter-project/imposter-jvm-engine/releases)

## Getting started
Expand Down Expand Up @@ -43,7 +43,7 @@ func main() {
configDir := "/path/to/imposter/config"

// register the engine implementation you want to use.
// swap for jvm.EnableEngine() or golang.EnableEngine() as required.
// swap for jvm.EnableEngine() or native.EnableEngine() as required.
docker.EnableEngine()

startOptions := engine.StartOptions{
Expand All @@ -67,11 +67,11 @@ The matching engine type constants live on the `engine` package:

- `engine.EngineTypeDockerCore` (paired with `docker.EnableEngine()`)
- `engine.EngineTypeJvmSingleJar` (paired with `jvm.EnableEngine()`)
- `engine.EngineTypeGolang` (paired with `golang.EnableEngine()`)
- `engine.EngineTypeNative` (paired with `native.EnableEngine()`)

## Learn more

- [Configuration reference](https://docs.imposter.sh/configuration/)
- [Docker Engine](./engine_docker.md)
- [JVM Engine](./engine_jvm.md)
- [Golang Engine](./engine_golang.md)
- [Native Engine](./engine_native.md)
22 changes: 18 additions & 4 deletions internal/engine/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,24 @@ const (
EngineTypeDockerDistroless EngineType = "docker-distroless"
EngineTypeJvmSingleJar EngineType = "jvm"
EngineTypeJvmUnpacked EngineType = "unpacked"
EngineTypeGolang EngineType = "golang"
EngineTypeNative EngineType = "native"
)
const defaultEngineType = EngineTypeDockerCore

// engineTypeAliases maps deprecated user-facing engine type names to their canonical form.
// Aliases are accepted on user input (CLI flag, env var, config file) but not surfaced in
// help text or shell completions.
var engineTypeAliases = map[EngineType]EngineType{
"golang": EngineTypeNative,
}

func normaliseEngineType(t EngineType) EngineType {
if canon, ok := engineTypeAliases[t]; ok {
return canon
}
return t
}

var logger = logging.GetLogger()

var (
Expand Down Expand Up @@ -103,7 +117,7 @@ func build(engineType EngineType, configDir string, startOptions StartOptions) M

func validateEngineType(engineType EngineType) error {
switch engineType {
case EngineTypeAwsLambda, EngineTypeDockerCore, EngineTypeDockerAll, EngineTypeDockerDistroless, EngineTypeJvmSingleJar, EngineTypeJvmUnpacked, EngineTypeGolang:
case EngineTypeAwsLambda, EngineTypeDockerCore, EngineTypeDockerAll, EngineTypeDockerDistroless, EngineTypeJvmSingleJar, EngineTypeJvmUnpacked, EngineTypeNative:
return nil
}
return fmt.Errorf("unsupported engine type: %v", engineType)
Expand All @@ -114,11 +128,11 @@ func GetConfiguredType(override string) EngineType {
}

func GetConfiguredTypeWithDefault(override string, defaultType EngineType) EngineType {
return EngineType(stringutil.GetFirstNonEmpty(
return normaliseEngineType(EngineType(stringutil.GetFirstNonEmpty(
override,
viper.GetString("engine"),
string(defaultType),
))
)))
}

func GetConfiguredVersion(engineType EngineType, override string, allowCached bool) string {
Expand Down
2 changes: 2 additions & 0 deletions internal/engine/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func TestGetConfiguredType(t *testing.T) {
{name: "return overridden engine type", args: args{override: "docker"}, want: "docker"},
{name: "return configured engine type", args: args{override: ""}, configureType: "jvm", want: "jvm"},
{name: "return default engine type", args: args{override: ""}, want: defaultEngineType},
{name: "normalise legacy golang override to native", args: args{override: "golang"}, want: EngineTypeNative},
{name: "normalise legacy golang config to native", args: args{override: ""}, configureType: "golang", want: EngineTypeNative},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading
Loading