diff --git a/README.md b/README.md index 1dc32fd..7ff8f5e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/cmd/common.go b/cmd/common.go index 411cc3f..2e33b9b 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -11,7 +11,7 @@ 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. @@ -19,7 +19,7 @@ var localTypes = []engine.EngineType{ var allEngineTypes = []engine.EngineType{ engine.EngineTypeDockerCore, engine.EngineTypeJvmSingleJar, - engine.EngineTypeGolang, + engine.EngineTypeNative, } // runWithRecovery executes fn, recovering from logger.Fatal calls that diff --git a/cmd/down.go b/cmd/down.go index 885c43d..d300b81 100644 --- a/cmd/down.go +++ b/cmd/down.go @@ -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) diff --git a/cmd/down_test.go b/cmd/down_test.go index 657d25e..a3204cd 100644 --- a/cmd/down_test.go +++ b/cmd/down_test.go @@ -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 { diff --git a/cmd/engine_list.go b/cmd/engine_list.go index d5203e3..6947303 100644 --- a/cmd/engine_list.go +++ b/cmd/engine_list.go @@ -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) } diff --git a/cmd/engine_pull.go b/cmd/engine_pull.go index 78c4ecc..8162f40 100644 --- a/cmd/engine_pull.go +++ b/cmd/engine_pull.go @@ -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) diff --git a/cmd/list.go b/cmd/list.go index 295f6e3..fe7c76e 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -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") diff --git a/cmd/list_test.go b/cmd/list_test.go index 13db285..10a7b98 100644 --- a/cmd/list_test.go +++ b/cmd/list_test.go @@ -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" @@ -30,7 +30,7 @@ import ( func init() { docker.EnableEngine() jvm.EnableSingleJarEngine() - golang.EnableEngine() + native.EnableEngine() } func Test_renderMocks_without_engine(t *testing.T) { @@ -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, }, } diff --git a/cmd/plugin.go b/cmd/plugin.go index ecf6a8d..ebeba07 100644 --- a/cmd/plugin.go +++ b/cmd/plugin.go @@ -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) } diff --git a/cmd/plugin_uninstall_test.go b/cmd/plugin_uninstall_test.go index 9fb2fb4..fb097df 100644 --- a/cmd/plugin_uninstall_test.go +++ b/cmd/plugin_uninstall_test.go @@ -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() @@ -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() diff --git a/cmd/up.go b/cmd/up.go index fd0ee2b..380be2a 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -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") diff --git a/cmd/version.go b/cmd/version.go index 81c64b8..0d4d0fe 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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) diff --git a/cmd/version_test.go b/cmd/version_test.go index 1d621fb..85b358d 100644 --- a/cmd/version_test.go +++ b/cmd/version_test.go @@ -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, diff --git a/docs/config.md b/docs/config.md index 5804c77..2aa2189 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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" @@ -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) diff --git a/docs/engine_docker.md b/docs/engine_docker.md index e9093ce..4bbb331 100644 --- a/docs/engine_docker.md +++ b/docs/engine_docker.md @@ -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 diff --git a/docs/engine_jvm.md b/docs/engine_jvm.md index b4759ae..39ecdaa 100644 --- a/docs/engine_jvm.md +++ b/docs/engine_jvm.md @@ -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 diff --git a/docs/engine_golang.md b/docs/engine_native.md similarity index 69% rename from docs/engine_golang.md rename to docs/engine_native.md index 4315364..58c83f7 100644 --- a/docs/engine_golang.md +++ b/docs/engine_native.md @@ -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) @@ -30,17 +32,17 @@ 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 @@ -48,11 +50,11 @@ You can also provide the `--engine-type` (or `-t`) command line argument to the 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 diff --git a/docs/engine_unpacked.md b/docs/engine_unpacked.md index 2789765..5a8ad21 100644 --- a/docs/engine_unpacked.md +++ b/docs/engine_unpacked.md @@ -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 diff --git a/docs/install.md b/docs/install.md index e50308b..97a17dd 100644 --- a/docs/install.md +++ b/docs/install.md @@ -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.** diff --git a/docs/sdk.md b/docs/sdk.md index a25895e..212d6be 100644 --- a/docs/sdk.md +++ b/docs/sdk.md @@ -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 @@ -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{ @@ -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) diff --git a/internal/engine/builder.go b/internal/engine/builder.go index e8642b8..b8faf54 100644 --- a/internal/engine/builder.go +++ b/internal/engine/builder.go @@ -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 ( @@ -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) @@ -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 { diff --git a/internal/engine/builder_test.go b/internal/engine/builder_test.go index 5d93d0d..a87f695 100644 --- a/internal/engine/builder_test.go +++ b/internal/engine/builder_test.go @@ -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) { diff --git a/internal/engine/golang/enable.go b/internal/engine/golang/enable.go deleted file mode 100644 index 8544934..0000000 --- a/internal/engine/golang/enable.go +++ /dev/null @@ -1,30 +0,0 @@ -package golang - -import ( - "path/filepath" - - "github.com/imposter-project/imposter-cli/internal/engine" -) - -var golangInitialised = false - -// EnableEngine registers the Golang engine implementation -func EnableEngine() { - if !golangInitialised { - golangInitialised = true - - engine.RegisterLibrary(engine.EngineTypeGolang, func() engine.EngineLibrary { - return NewLibrary() - }) - engine.RegisterEngine(engine.EngineTypeGolang, func(configDir string, startOptions engine.StartOptions) engine.MockEngine { - lib := NewLibrary() - binCachePath, err := lib.ensureBinCache() - if err != nil { - providerLogger.Fatal(err) - } - versionedBinDir := filepath.Join(binCachePath, startOptions.Version) - provider := NewProvider(startOptions.Version, versionedBinDir) - return NewGolangMockEngine(configDir, startOptions, provider) - }) - } -} diff --git a/internal/engine/meta.go b/internal/engine/meta.go index c620cf2..ee967f9 100644 --- a/internal/engine/meta.go +++ b/internal/engine/meta.go @@ -3,7 +3,7 @@ package engine // getRepoNameForEngineType returns the GitHub repository name for the given engine type. func getRepoNameForEngineType(engineType EngineType) string { switch engineType { - case EngineTypeGolang: + case EngineTypeNative: return "imposter-go" default: return "imposter-jvm-engine" diff --git a/internal/engine/native/enable.go b/internal/engine/native/enable.go new file mode 100644 index 0000000..6d06eff --- /dev/null +++ b/internal/engine/native/enable.go @@ -0,0 +1,35 @@ +package native + +import ( + "path/filepath" + + "github.com/imposter-project/imposter-cli/internal/engine" + "github.com/spf13/viper" +) + +var nativeInitialised = false + +// EnableEngine registers the native engine implementation +func EnableEngine() { + if !nativeInitialised { + nativeInitialised = true + + // Accept the legacy "golang.binCache" config key as an alias for "native.binCache" + // so existing config files and IMPOSTER_GOLANG_BINCACHE env vars keep working. + viper.RegisterAlias("golang.binCache", "native.binCache") + + engine.RegisterLibrary(engine.EngineTypeNative, func() engine.EngineLibrary { + return NewLibrary() + }) + engine.RegisterEngine(engine.EngineTypeNative, func(configDir string, startOptions engine.StartOptions) engine.MockEngine { + lib := NewLibrary() + binCachePath, err := lib.ensureBinCache() + if err != nil { + providerLogger.Fatal(err) + } + versionedBinDir := filepath.Join(binCachePath, startOptions.Version) + provider := NewProvider(startOptions.Version, versionedBinDir) + return NewNativeMockEngine(configDir, startOptions, provider) + }) + } +} diff --git a/internal/engine/golang/engine.go b/internal/engine/native/engine.go similarity index 74% rename from internal/engine/golang/engine.go rename to internal/engine/native/engine.go index aa03196..702d276 100644 --- a/internal/engine/golang/engine.go +++ b/internal/engine/native/engine.go @@ -1,4 +1,4 @@ -package golang +package native import ( "fmt" @@ -16,8 +16,8 @@ import ( var logger = logging.GetLogger() -// GolangMockEngine implements the MockEngine interface for the golang implementation -type GolangMockEngine struct { +// NativeMockEngine implements the MockEngine interface for the native binary implementation +type NativeMockEngine struct { configDir string options engine.StartOptions provider *Provider @@ -26,9 +26,9 @@ type GolangMockEngine struct { shutDownC chan bool } -// NewGolangMockEngine creates a new instance of the golang mock engine -func NewGolangMockEngine(configDir string, options engine.StartOptions, provider *Provider) *GolangMockEngine { - return &GolangMockEngine{ +// NewNativeMockEngine creates a new instance of the native mock engine +func NewNativeMockEngine(configDir string, options engine.StartOptions, provider *Provider) *NativeMockEngine { + return &NativeMockEngine{ configDir: configDir, options: options, provider: provider, @@ -37,13 +37,13 @@ func NewGolangMockEngine(configDir string, options engine.StartOptions, provider } } -func (g *GolangMockEngine) Start(wg *sync.WaitGroup) bool { +func (g *NativeMockEngine) Start(wg *sync.WaitGroup) bool { return g.startWithOptions(wg, g.options) } -func (g *GolangMockEngine) startWithOptions(wg *sync.WaitGroup, options engine.StartOptions) (success bool) { +func (g *NativeMockEngine) startWithOptions(wg *sync.WaitGroup, options engine.StartOptions) (success bool) { if len(options.DirMounts) > 0 { - logger.Warnf("golang engine does not support directory mounts - these will be ignored") + logger.Warnf("native engine does not support directory mounts - these will be ignored") } env := g.buildEnv(options) command := (*g.provider).GetStartCommand([]string{}, env) @@ -51,11 +51,11 @@ func (g *GolangMockEngine) startWithOptions(wg *sync.WaitGroup, options engine.S command.Stderr = os.Stderr if err := command.Start(); err != nil { - logger.Errorf("failed to start golang mock engine: %v", err) + logger.Errorf("failed to start native mock engine: %v", err) return false } g.debouncer.Register(wg, strconv.Itoa(command.Process.Pid)) - logger.Trace("starting golang mock engine") + logger.Trace("starting native mock engine") g.cmd = command // watch in case process stops @@ -65,7 +65,7 @@ func (g *GolangMockEngine) startWithOptions(wg *sync.WaitGroup, options engine.S return up } -func (g *GolangMockEngine) buildEnv(options engine.StartOptions) []string { +func (g *NativeMockEngine) buildEnv(options engine.StartOptions) []string { env := engine.BuildEnv(options, engine.EnvOptions{IncludeHome: true, IncludePath: true}) env = append(env, fmt.Sprintf("IMPOSTER_PORT=%d", options.Port), @@ -85,14 +85,14 @@ func (g *GolangMockEngine) buildEnv(options engine.StartOptions) []string { logger.Tracef("plugins are disabled") } if options.EnableFileCache { - logger.Tracef("file cache not supported by golang engine") + logger.Tracef("file cache not supported by native engine") } logger.Tracef("engine environment: %v", env) return env } -func (g *GolangMockEngine) Stop(wg *sync.WaitGroup) { +func (g *NativeMockEngine) Stop(wg *sync.WaitGroup) { if g.cmd == nil { logger.Tracef("no process to remove") wg.Done() @@ -111,12 +111,12 @@ func (g *GolangMockEngine) Stop(wg *sync.WaitGroup) { g.notifyOnStopBlocking(wg) } -func (g *GolangMockEngine) StopImmediately(wg *sync.WaitGroup) { +func (g *NativeMockEngine) StopImmediately(wg *sync.WaitGroup) { go func() { g.shutDownC <- true }() g.Stop(wg) } -func (g *GolangMockEngine) Restart(wg *sync.WaitGroup) { +func (g *NativeMockEngine) Restart(wg *sync.WaitGroup) { wg.Add(1) g.Stop(wg) @@ -128,7 +128,7 @@ func (g *GolangMockEngine) Restart(wg *sync.WaitGroup) { wg.Done() } -func (g *GolangMockEngine) notifyOnStopBlocking(wg *sync.WaitGroup) { +func (g *NativeMockEngine) notifyOnStopBlocking(wg *sync.WaitGroup) { if g.cmd == nil || g.cmd.Process == nil { logger.Trace("no subprocess - notifying immediately") g.debouncer.Notify(wg, debounce.AtMostOnceEvent{}) @@ -149,11 +149,11 @@ func (g *GolangMockEngine) notifyOnStopBlocking(wg *sync.WaitGroup) { } } -func (g *GolangMockEngine) ListAllManaged() ([]engine.ManagedMock, error) { +func (g *NativeMockEngine) ListAllManaged() ([]engine.ManagedMock, error) { return procutil.FindImposterProcesses(matcher) } -func (g *GolangMockEngine) StopAllManaged() int { +func (g *NativeMockEngine) StopAllManaged() int { count, err := procutil.StopManagedProcesses(matcher) if err != nil { logger.Fatal(err) @@ -161,7 +161,7 @@ func (g *GolangMockEngine) StopAllManaged() int { return count } -func (g *GolangMockEngine) GetVersionString() (string, error) { +func (g *NativeMockEngine) GetVersionString() (string, error) { // TODO get from binary return g.options.Version, nil } diff --git a/internal/engine/golang/engine_test.go b/internal/engine/native/engine_test.go similarity index 93% rename from internal/engine/golang/engine_test.go rename to internal/engine/native/engine_test.go index d4e3032..9b74ded 100644 --- a/internal/engine/golang/engine_test.go +++ b/internal/engine/native/engine_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package golang +package native import ( "github.com/imposter-project/imposter-cli/internal/engine" @@ -26,7 +26,7 @@ import ( ) var engineBuilder = func(tt enginetests.EngineTestScenario) engine.MockEngine { - return engine.BuildEngine("golang", tt.Fields.ConfigDir, tt.Fields.Options) + return engine.BuildEngine("native", tt.Fields.ConfigDir, tt.Fields.Options) } func init() { @@ -43,7 +43,7 @@ func TestEngine_StartStop(t *testing.T) { tests := []enginetests.EngineTestScenario{ { - Name: "start golang engine", + Name: "start native engine", Fields: enginetests.EngineTestFields{ ConfigDir: testConfigPath, Options: engine.StartOptions{ @@ -68,7 +68,7 @@ func TestEngine_Restart(t *testing.T) { tests := []enginetests.EngineTestScenario{ { - Name: "restart golang engine", + Name: "restart native engine", Fields: enginetests.EngineTestFields{ ConfigDir: testConfigPath, Options: engine.StartOptions{ @@ -93,7 +93,7 @@ func TestEngine_List(t *testing.T) { tests := []enginetests.EngineTestScenario{ { - Name: "list golang engine", + Name: "list native engine", Fields: enginetests.EngineTestFields{ ConfigDir: testConfigPath, Options: engine.StartOptions{ diff --git a/internal/engine/golang/library.go b/internal/engine/native/library.go similarity index 84% rename from internal/engine/golang/library.go rename to internal/engine/native/library.go index e19ac75..c3efc86 100644 --- a/internal/engine/golang/library.go +++ b/internal/engine/native/library.go @@ -1,4 +1,4 @@ -package golang +package native import ( "fmt" @@ -9,14 +9,14 @@ import ( "github.com/imposter-project/imposter-cli/internal/engine" ) -const binCacheDir = ".imposter/engines/golang" +const binCacheDir = ".imposter/engines/native" -// Library implements the engine.EngineLibrary interface for the golang engine +// Library implements the engine.EngineLibrary interface for the native engine type Library struct { binCache string } -// NewLibrary creates a new instance of the golang engine library +// NewLibrary creates a new instance of the native engine library func NewLibrary() *Library { return &Library{} } @@ -38,7 +38,7 @@ func (l *Library) List() ([]engine.EngineMetadata, error) { for _, file := range files { if file.IsDir() { available = append(available, engine.EngineMetadata{ - EngineType: engine.EngineTypeGolang, + EngineType: engine.EngineTypeNative, Version: file.Name(), }) } @@ -64,5 +64,5 @@ func (l *Library) ShouldEnsurePlugins() bool { } func (l *Library) ensureBinCache() (string, error) { - return library.EnsureDirUsingConfig("golang.binCache", binCacheDir) + return library.EnsureDirUsingConfig("native.binCache", binCacheDir) } diff --git a/internal/engine/golang/processes.go b/internal/engine/native/processes.go similarity index 97% rename from internal/engine/golang/processes.go rename to internal/engine/native/processes.go index 9d7b1ed..dff6866 100644 --- a/internal/engine/golang/processes.go +++ b/internal/engine/native/processes.go @@ -1,4 +1,4 @@ -package golang +package native import ( "strconv" diff --git a/internal/engine/golang/provider.go b/internal/engine/native/provider.go similarity index 93% rename from internal/engine/golang/provider.go rename to internal/engine/native/provider.go index 034d700..6b93aa5 100644 --- a/internal/engine/golang/provider.go +++ b/internal/engine/native/provider.go @@ -1,4 +1,4 @@ -package golang +package native import ( "fmt" @@ -26,14 +26,14 @@ var downloadConfig = library.NewDownloadConfig( false, ) -// Provider handles downloading and managing the golang binary +// Provider handles downloading and managing the native binary type Provider struct { version string binDir string binaryPath string } -// NewProvider creates a new golang provider instance +// NewProvider creates a new native provider instance func NewProvider(version string, binDir string) *Provider { return &Provider{ version: version, @@ -126,16 +126,16 @@ func downloadAndExtractBinary(version string, binDir string) error { } func (p *Provider) GetEngineType() engine.EngineType { - return engine.EngineTypeGolang + return engine.EngineTypeNative } func (p *Provider) Build(configDir string, startOptions engine.StartOptions) engine.MockEngine { - return NewGolangMockEngine(configDir, startOptions, p) + return NewNativeMockEngine(configDir, startOptions, p) } func (p *Provider) Bundle(configDir string, dest string) error { // TODO: Implement if required - return fmt.Errorf("bundling not implemented for golang engine") + return fmt.Errorf("bundling not implemented for native engine") } func (p *Provider) GetStartCommand(args []string, env []string) *exec.Cmd { diff --git a/internal/plugin/configs.go b/internal/plugin/configs.go index 9fe8168..378bd64 100644 --- a/internal/plugin/configs.go +++ b/internal/plugin/configs.go @@ -20,7 +20,7 @@ type pluginConfiguration struct { } var pluginConfigs = map[string]pluginConfiguration{ - "golang": { + "native": { downloadConfig: library2.NewDownloadConfig( "https://github.com/imposter-project/imposter-go-plugins/releases/latest/download", "https://github.com/imposter-project/imposter-go-plugins/releases/download/v%v", @@ -46,8 +46,8 @@ var pluginConfigs = map[string]pluginConfiguration{ // determinePluginConfig returns the plugin configuration based on the engine type. func determinePluginConfig(engineType engine.EngineType) pluginConfiguration { switch engineType { - case engine.EngineTypeGolang: - return pluginConfigs["golang"] + case engine.EngineTypeNative: + return pluginConfigs["native"] default: return pluginConfigs["*"] } diff --git a/internal/plugin/edge_cases_test.go b/internal/plugin/edge_cases_test.go index f260f63..fed4ba2 100644 --- a/internal/plugin/edge_cases_test.go +++ b/internal/plugin/edge_cases_test.go @@ -25,8 +25,8 @@ func TestGetPluginRemoteFileName(t *testing.T) { wantErr: false, }, { - name: "golang plugin remote filename", - engineType: engine.EngineTypeGolang, + name: "native plugin remote filename", + engineType: engine.EngineTypeNative, pluginName: "swaggerui", want: fmt.Sprintf("plugin-swaggerui_%s_%s.zip", runtime.GOOS, runtime.GOARCH), wantErr: false, diff --git a/internal/plugin/files_test.go b/internal/plugin/files_test.go index c986073..bf663f5 100644 --- a/internal/plugin/files_test.go +++ b/internal/plugin/files_test.go @@ -19,7 +19,7 @@ func Test_buildPluginFileName(t *testing.T) { want string }{ { - name: "golang plugin local file", + name: "native plugin local file", pluginConfig: pluginConfiguration{ localFileTemplate: "plugin-{{ .PluginName }}", remoteFileTemplate: "plugin-{{ .PluginName }}_{{ .OS }}_{{ .Arch }}{{ .Ext }}", @@ -31,7 +31,7 @@ func Test_buildPluginFileName(t *testing.T) { want: "plugin-test-plugin", }, { - name: "golang plugin remote file", + name: "native plugin remote file", pluginConfig: pluginConfiguration{ localFileTemplate: "plugin-{{ .PluginName }}", remoteFileTemplate: "plugin-{{ .PluginName }}_{{ .OS }}_{{ .Arch }}{{ .Ext }}", @@ -135,8 +135,8 @@ func Test_GetPluginLocalPath(t *testing.T) { wantErr: false, }, { - name: "get plugin local path for golang plugin", - args: args{pluginName: "swaggerui", engineType: engine.EngineTypeGolang, version: "1.2.2"}, + name: "get plugin local path for native plugin", + args: args{pluginName: "swaggerui", engineType: engine.EngineTypeNative, version: "1.2.2"}, wantFullPluginFileName: func() string { if runtime.GOOS == "windows" { return "plugin-swaggerui.exe" @@ -180,8 +180,8 @@ func Test_getPluginFileName(t *testing.T) { wantErr bool }{ { - name: "golang plugin local name", - engineType: engine.EngineTypeGolang, + name: "native plugin local name", + engineType: engine.EngineTypeNative, pluginName: "swaggerui", remote: false, want: func() string { @@ -193,8 +193,8 @@ func Test_getPluginFileName(t *testing.T) { wantErr: false, }, { - name: "golang plugin remote name", - engineType: engine.EngineTypeGolang, + name: "native plugin remote name", + engineType: engine.EngineTypeNative, pluginName: "swaggerui", remote: true, want: fmt.Sprintf("plugin-swaggerui_%s_%s.zip", runtime.GOOS, runtime.GOARCH), @@ -263,14 +263,14 @@ func Test_isValidPluginFile(t *testing.T) { wantPluginName: "", }, { - name: "valid golang plugin file", + name: "valid native plugin file", candidateFile: func() string { if runtime.GOOS == "windows" { return "plugin-swaggerui.exe" } return "plugin-swaggerui" }(), - engineType: engine.EngineTypeGolang, + engineType: engine.EngineTypeNative, wantValid: true, wantPluginName: "swaggerui", }, diff --git a/internal/plugin/list_test.go b/internal/plugin/list_test.go index d518a38..fb8019d 100644 --- a/internal/plugin/list_test.go +++ b/internal/plugin/list_test.go @@ -63,8 +63,8 @@ func TestList(t *testing.T) { expectError: false, }, { - name: "golang plugin", - engineType: engine.EngineTypeGolang, + name: "native plugin", + engineType: engine.EngineTypeNative, version: version, setupFiles: func() []string { if runtime.GOOS == "windows" { diff --git a/internal/plugin/uninstall_test.go b/internal/plugin/uninstall_test.go index 5056050..c80f6ef 100644 --- a/internal/plugin/uninstall_test.go +++ b/internal/plugin/uninstall_test.go @@ -48,9 +48,9 @@ func TestUninstallPlugin(t *testing.T) { expectError: false, }, { - name: "uninstall existing golang plugin", + name: "uninstall existing native plugin", pluginName: "swaggerui", - engineType: engine.EngineTypeGolang, + engineType: engine.EngineTypeNative, version: version, setupFile: true, expectRemoved: true, diff --git a/main.go b/main.go index e672668..6ccb980 100644 --- a/main.go +++ b/main.go @@ -28,8 +28,8 @@ import ( "github.com/imposter-project/imposter-cli/cmd" awslambdaengine "github.com/imposter-project/imposter-cli/internal/engine/awslambda" "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" ) const defaultLogLevel = "debug" @@ -44,7 +44,7 @@ func main() { docker.EnableEngine() jvm.EnableSingleJarEngine() jvm.EnableUnpackedDistroEngine() - golang.EnableEngine() + native.EnableEngine() // remotes awslambda.Register()