Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Apr 1, 2021
1 parent f360cc8 commit 512a87f
Show file tree
Hide file tree
Showing 26 changed files with 589 additions and 273 deletions.
32 changes: 16 additions & 16 deletions pkg/cmd/extension/build/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/tetratelabs/getenvoy/pkg/test/cmd/extension"
cmd2 "github.com/tetratelabs/getenvoy/pkg/test/cmd"
cmdutil "github.com/tetratelabs/getenvoy/pkg/util/cmd"
)

Expand Down Expand Up @@ -51,9 +51,9 @@ func TestGetEnvoyExtensionBuildValidateFlag(t *testing.T) {
for _, test := range tests {
test := test // pin! see https://github.com/kyoh86/scopelint for why

t.Run(test.flag, func(t *testing.T) {
t.Run(test.flag+"="+test.flagValue, func(t *testing.T) {
// Run "getenvoy extension build" with the flags we are testing
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "build", test.flag, test.flagValue})
err := cmdutil.Execute(cmd)
require.EqualError(t, err, test.expectedErr, `expected an error running [%v]`, cmd)
Expand All @@ -68,11 +68,11 @@ func TestGetEnvoyExtensionBuildValidateFlag(t *testing.T) {

func TestGetEnvoyExtensionBuildFailsOutsideWorkspaceDirectory(t *testing.T) {
// Change to a non-workspace dir
dir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir+"/..")
dir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir+"/..")
defer revertWd()

// Run "getenvoy extension build"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "build"})
err := cmdutil.Execute(cmd)

Expand All @@ -86,20 +86,20 @@ func TestGetEnvoyExtensionBuildFailsOutsideWorkspaceDirectory(t *testing.T) {

func TestGetEnvoyExtensionBuild(t *testing.T) {
// We use a fake docker command to capture the commandline that would be invoked
dockerDir, revertPath := extension.RequireOverridePath(t, extension.FakeDockerDir)
dockerDir, revertPath := cmd2.RequireOverridePath(t, cmd2.FakeDockerDir)
defer revertPath()

// "getenvoy extension build" must be in a valid workspace directory
workspaceDir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir)
workspaceDir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir)
defer revertWd()

// Fake the current user so we can test it is used in the docker args
expectedUser := user.User{Uid: "1001", Gid: "1002"}
revertGetCurrentUser := extension.OverrideGetCurrentUser(&expectedUser)
revertGetCurrentUser := cmd2.OverrideGetCurrentUser(&expectedUser)
defer revertGetCurrentUser()

// Run "getenvoy extension build"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "build"})
err := cmdutil.Execute(cmd)

Expand All @@ -116,15 +116,15 @@ func TestGetEnvoyExtensionBuild(t *testing.T) {
// This tests --toolchain-container flags become docker command options
func TestGetEnvoyExtensionBuildWithDockerOptions(t *testing.T) {
// We use a fake docker command to capture the commandline that would be invoked
_, revertPath := extension.RequireOverridePath(t, extension.FakeDockerDir)
_, revertPath := cmd2.RequireOverridePath(t, cmd2.FakeDockerDir)
defer revertPath()

// "getenvoy extension build" must be in a valid workspace directory
_, revertWd := extension.RequireChDir(t, relativeWorkspaceDir)
_, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir)
defer revertWd()

// Run "getenvoy extension build"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "build",
"--toolchain-container-image", "build/image",
"--toolchain-container-options", `-e 'VAR=VALUE' -v "/host:/container"`,
Expand All @@ -140,22 +140,22 @@ func TestGetEnvoyExtensionBuildWithDockerOptions(t *testing.T) {
// TestGetEnvoyExtensionBuildFail ensures build failures show useful information in stderr
func TestGetEnvoyExtensionBuildFail(t *testing.T) {
// We use a fake docker command to capture the commandline that would be invoked, and force a failure.
dockerDir, revertPath := extension.RequireOverridePath(t, extension.FakeDockerDir)
dockerDir, revertPath := cmd2.RequireOverridePath(t, cmd2.FakeDockerDir)
defer revertPath()

// "getenvoy extension build" must be in a valid workspace directory
workspaceDir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir)
workspaceDir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir)
defer revertWd()

// Fake the current user so we can test it is used in the docker args
expectedUser := user.User{Uid: "1001", Gid: "1002"}
revertGetCurrentUser := extension.OverrideGetCurrentUser(&expectedUser)
revertGetCurrentUser := cmd2.OverrideGetCurrentUser(&expectedUser)
defer revertGetCurrentUser()

// "-e DOCKER_EXIT_CODE=3" is a special instruction handled in the fake docker script
toolchainOptions := "-e DOCKER_EXIT_CODE=3"
// Run "getenvoy extension build"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "build", "--toolchain-container-options", toolchainOptions})
err := cmdutil.Execute(cmd)

Expand Down
34 changes: 17 additions & 17 deletions pkg/cmd/extension/clean/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

"github.com/stretchr/testify/require"

"github.com/tetratelabs/getenvoy/pkg/test/cmd/extension"
cmd2 "github.com/tetratelabs/getenvoy/pkg/test/cmd"
cmdutil "github.com/tetratelabs/getenvoy/pkg/util/cmd"
)

// relativeWorkspaceDir points to a usable pre-initialized workspace
const relativeWorkspaceDir = "../build/testdata/workspace"
const relativeWorkspaceDir = "testdata/workspace"

func TestGetEnvoyExtensionCleanValidateFlag(t *testing.T) {
type testCase struct {
Expand All @@ -51,9 +51,9 @@ func TestGetEnvoyExtensionCleanValidateFlag(t *testing.T) {
for _, test := range tests {
test := test // pin! see https://github.com/kyoh86/scopelint for why

t.Run(test.flag, func(t *testing.T) {
t.Run(test.flag+"="+test.flagValue, func(t *testing.T) {
// Run "getenvoy extension clean" with the flags we are testing
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "clean", test.flag, test.flagValue})
err := cmdutil.Execute(cmd)
require.EqualError(t, err, test.expectedErr, `expected an error running [%v]`, cmd)
Expand All @@ -68,11 +68,11 @@ func TestGetEnvoyExtensionCleanValidateFlag(t *testing.T) {

func TestGetEnvoyExtensionCleanFailsOutsideWorkspaceDirectory(t *testing.T) {
// Change to a non-workspace dir
dir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir+"/..")
dir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir+"/..")
defer revertWd()

// Run "getenvoy extension clean"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "clean"})
err := cmdutil.Execute(cmd)

Expand All @@ -86,20 +86,20 @@ func TestGetEnvoyExtensionCleanFailsOutsideWorkspaceDirectory(t *testing.T) {

func TestGetEnvoyExtensionClean(t *testing.T) {
// We use a fake docker command to capture the commandline that would be invoked
dockerDir, revertPath := extension.RequireOverridePath(t, extension.FakeDockerDir)
dockerDir, revertPath := cmd2.RequireOverridePath(t, cmd2.FakeDockerDir)
defer revertPath()

// "getenvoy extension clean" must be in a valid workspace directory
workspaceDir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir)
workspaceDir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir)
defer revertWd()

// Fake the current user so we can test it is used in the docker args
expectedUser := user.User{Uid: "1001", Gid: "1002"}
revertGetCurrentUser := extension.OverrideGetCurrentUser(&expectedUser)
revertGetCurrentUser := cmd2.OverrideGetCurrentUser(&expectedUser)
defer revertGetCurrentUser()

// Run "getenvoy extension clean"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "clean"})
err := cmdutil.Execute(cmd)

Expand All @@ -116,15 +116,15 @@ func TestGetEnvoyExtensionClean(t *testing.T) {
// This tests --toolchain-container flags become docker command options
func TestGetEnvoyExtensionCleanWithDockerOptions(t *testing.T) {
// We use a fake docker command to capture the commandline that would be invoked
_, revertPath := extension.RequireOverridePath(t, extension.FakeDockerDir)
_, revertPath := cmd2.RequireOverridePath(t, cmd2.FakeDockerDir)
defer revertPath()

// "getenvoy extension clean" must be in a valid workspace directory
_, revertWd := extension.RequireChDir(t, relativeWorkspaceDir)
_, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir)
defer revertWd()

// Run "getenvoy extension clean"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "clean",
"--toolchain-container-image", "clean/image",
"--toolchain-container-options", `-e 'VAR=VALUE' -v "/host:/container"`,
Expand All @@ -140,22 +140,22 @@ func TestGetEnvoyExtensionCleanWithDockerOptions(t *testing.T) {
// TestGetEnvoyExtensionCleanFail ensures clean failures show useful information in stderr
func TestGetEnvoyExtensionCleanFail(t *testing.T) {
// We use a fake docker command to capture the commandline that would be invoked, and force a failure.
dockerDir, revertPath := extension.RequireOverridePath(t, extension.FakeDockerDir)
dockerDir, revertPath := cmd2.RequireOverridePath(t, cmd2.FakeDockerDir)
defer revertPath()

// "getenvoy extension clean" must be in a valid workspace directory
workspaceDir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir)
workspaceDir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir)
defer revertWd()

// Fake the current user so we can test it is used in the docker args
expectedUser := user.User{Uid: "1001", Gid: "1002"}
revertGetCurrentUser := extension.OverrideGetCurrentUser(&expectedUser)
revertGetCurrentUser := cmd2.OverrideGetCurrentUser(&expectedUser)
defer revertGetCurrentUser()

// "-e DOCKER_EXIT_CODE=3" is a special instruction handled in the fake docker script
toolchainOptions := "-e DOCKER_EXIT_CODE=3"
// Run "getenvoy extension clean"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "clean", "--toolchain-container-options", toolchainOptions})
err := cmdutil.Execute(cmd)

Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/extension/clean/testdata/.licenserignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/workspace/
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Envoy Wasm extension created with getenvoy toolkit.
#
kind: Extension

name: mycompany.filters.http.custom_metrics

category: envoy.filters.http
language: rust

# Runtime the extension is being developed against.
runtime:
envoy:
version: standard:1.17.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kind: BuiltinToolchain
16 changes: 8 additions & 8 deletions pkg/cmd/extension/push/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/tetratelabs/getenvoy/pkg/test/cmd/extension"
cmd2 "github.com/tetratelabs/getenvoy/pkg/test/cmd"
cmdutil "github.com/tetratelabs/getenvoy/pkg/util/cmd"
)

Expand All @@ -37,11 +37,11 @@ const defaultTag = "latest"

// TestGetEnvoyExtensionPush shows current directory is usable, provided it is a valid workspace.
func TestGetEnvoyExtensionPush(t *testing.T) {
_, revertWd := extension.RequireChDir(t, relativeWorkspaceDir)
_, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir)
defer revertWd()

// Run "getenvoy extension push localhost:5000/getenvoy/sample"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "push", localRegistryWasmImageRef})
err := cmdutil.Execute(cmd)

Expand All @@ -59,11 +59,11 @@ digest: sha256`, defaultTag, imageRef), `unexpected stderr after running [%v]`,

func TestGetEnvoyExtensionPushFailsOutsideWorkspaceDirectory(t *testing.T) {
// Change to a non-workspace dir
dir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir+"/..")
dir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir+"/..")
defer revertWd()

// Run "getenvoy extension push localhost:5000/getenvoy/sample"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "push", localRegistryWasmImageRef})
err := cmdutil.Execute(cmd)

Expand All @@ -75,17 +75,17 @@ func TestGetEnvoyExtensionPushFailsOutsideWorkspaceDirectory(t *testing.T) {
require.Equal(t, expectedStderr, stderr.String(), `expected stderr running [%v]`, cmd)
}

// TestGetEnvoyExtensionPushWithExplicitFileOption shows
// TestGetEnvoyExtensionPushWithExplicitFileOption shows we don't need to be in a workspace directory to push a wasm.
func TestGetEnvoyExtensionPushWithExplicitFileOption(t *testing.T) {
// Change to a non-workspace dir
dir, revertWd := extension.RequireChDir(t, relativeWorkspaceDir+"/..")
dir, revertWd := cmd2.RequireChDir(t, relativeWorkspaceDir+"/..")
defer revertWd()

// Point to a wasm file explicitly
wasm := filepath.Join(dir, "workspace", "extension.wasm")

// Run "getenvoy extension push localhost:5000/getenvoy/sample --extension-file testdata/workspace/extension.wasm"
cmd, stdout, stderr := extension.NewRootCommand()
cmd, stdout, stderr := cmd2.NewRootCommand()
cmd.SetArgs([]string{"extension", "push", localRegistryWasmImageRef, "--extension-file", wasm})
err := cmdutil.Execute(cmd)

Expand Down
Loading

0 comments on commit 512a87f

Please sign in to comment.