Repository: tetratelabs/getenvoy
Pull request #226 (2021-05-19 01:19:58)

Adds help test to ensure we know what changes
This helps prepare for #218

codefromthecrypt: merging as I don't think this one has anything notable

Patch:
diff --git a/pkg/cmd/fetch.go b/pkg/cmd/fetch.go
index 0a9b2ff..20698c7 100644
--- a/pkg/cmd/fetch.go
+++ b/pkg/cmd/fetch.go
@@ -31,8 +31,8 @@ func NewFetchCmd(o *globals.GlobalOpts) *cobra.Command {
 		Short: "Downloads a version of Envoy. Available builds can be retrieved using `getenvoy list`.",
 		Example: fmt.Sprintf(`# Fetch using a partial manifest reference to retrieve a build suitable for your operating system.
 getenvoy fetch %[1]s
-		
-# Fetch using a full manifest reference to retrieve a specific build for Linux. 
+
+# Fetch using a full manifest reference to retrieve a specific build for Linux.
 getenvoy fetch %[1]s/linux-glibc`, reference.Latest),
 		Args: validateReferenceArg,
 		RunE: func(cmd *cobra.Command, args []string) error {


Test patch:
diff --git a/pkg/cmd/help_test.go b/pkg/cmd/help_test.go
new file mode 100644
index 0000000..ac9b1dc
--- /dev/null
+++ b/pkg/cmd/help_test.go
@@ -0,0 +1,52 @@
+// Copyright 2021 Tetrate
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cmd_test
+
+import (
+	"fmt"
+	"os"
+	"path/filepath"
+	"strings"
+	"testing"
+
+	"github.com/stretchr/testify/require"
+
+	"github.com/tetratelabs/getenvoy/internal/reference"
+	"github.com/tetratelabs/getenvoy/pkg/globals"
+)
+
+func TestGetEnvoyHelp(t *testing.T) {
+	for _, command := range []string{"", "fetch", "list", "run"} {
+		command := command
+		t.Run(command, func(t *testing.T) {
+			c, stdout, _ := newApp(&globals.GlobalOpts{})
+			args := []string{"help"}
+			if command != "" {
+				args = append(args, command)
+			}
+			c.SetArgs(args)
+			require.NoError(t, c.Execute())
+
+			expected := "getenvoy_help.txt"
+			if command != "" {
+				expected = fmt.Sprintf("getenvoy_%s_help.txt", command)
+			}
+
+			want, err := os.ReadFile(filepath.Join("testdata", expected))
+			require.NoError(t, err)
+			require.Equal(t, strings.ReplaceAll(string(want), "VERSION", reference.Latest), stdout.String())
+		})
+	}
+}
diff --git a/pkg/cmd/testdata/getenvoy_fetch.md b/pkg/cmd/testdata/getenvoy_fetch.md
index 2daa7a2..9652e51 100644
--- a/pkg/cmd/testdata/getenvoy_fetch.md
+++ b/pkg/cmd/testdata/getenvoy_fetch.md
@@ -17,8 +17,8 @@ getenvoy fetch <reference> [flags]
 ```
 # Fetch using a partial manifest reference to retrieve a build suitable for your operating system.
 getenvoy fetch VERSION
-		
-# Fetch using a full manifest reference to retrieve a specific build for Linux. 
+
+# Fetch using a full manifest reference to retrieve a specific build for Linux.
 getenvoy fetch VERSION/linux-glibc
 ```
 
diff --git a/pkg/cmd/testdata/getenvoy_fetch_help.txt b/pkg/cmd/testdata/getenvoy_fetch_help.txt
new file mode 100644
index 0000000..bd679b8
--- /dev/null
+++ b/pkg/cmd/testdata/getenvoy_fetch_help.txt
@@ -0,0 +1,17 @@
+Downloads a version of Envoy. Available builds can be retrieved using `getenvoy list`.
+
+Usage:
+  getenvoy fetch <reference> [flags]
+
+Examples:
+# Fetch using a partial manifest reference to retrieve a build suitable for your operating system.
+getenvoy fetch VERSION
+
+# Fetch using a full manifest reference to retrieve a specific build for Linux.
+getenvoy fetch VERSION/linux-glibc
+
+Flags:
+  -h, --help   help for fetch
+
+Global Flags:
+      --home-dir string   GetEnvoy home directory (location of downloaded artifacts, caches, etc)
diff --git a/pkg/cmd/testdata/getenvoy_help.txt b/pkg/cmd/testdata/getenvoy_help.txt
new file mode 100644
index 0000000..b31caf9
--- /dev/null
+++ b/pkg/cmd/testdata/getenvoy_help.txt
@@ -0,0 +1,16 @@
+Manage Envoy lifecycle including fetching binaries and collection of process state.
+
+Usage:
+  getenvoy [command]
+
+Available Commands:
+  fetch       Downloads a version of Envoy. Available builds can be retrieved using `getenvoy list`.
+  help        Help about any command
+  list        List available Envoy version references you can run
+  run         Runs Envoy and collects process state on exit. Available builds can be retrieved using `getenvoy list`.
+
+Flags:
+  -h, --help              help for getenvoy
+      --home-dir string   GetEnvoy home directory (location of downloaded artifacts, caches, etc)
+
+Use "getenvoy [command] --help" for more information about a command.
diff --git a/pkg/cmd/testdata/getenvoy_list_help.txt b/pkg/cmd/testdata/getenvoy_list_help.txt
new file mode 100644
index 0000000..a2d8228
--- /dev/null
+++ b/pkg/cmd/testdata/getenvoy_list_help.txt
@@ -0,0 +1,10 @@
+List available Envoy version references you can run
+
+Usage:
+  getenvoy list [flags]
+
+Flags:
+  -h, --help   help for list
+
+Global Flags:
+      --home-dir string   GetEnvoy home directory (location of downloaded artifacts, caches, etc)
diff --git a/pkg/cmd/testdata/getenvoy_run_help.txt b/pkg/cmd/testdata/getenvoy_run_help.txt
new file mode 100644
index 0000000..8c97bf5
--- /dev/null
+++ b/pkg/cmd/testdata/getenvoy_run_help.txt
@@ -0,0 +1,18 @@
+Runs Envoy and collects process state on exit. Available builds can be retrieved using `getenvoy list`.
+
+Usage:
+  getenvoy run reference [flags] [-- <envoy-args>]
+
+Examples:
+# Run using a manifest reference.
+getenvoy run VERSION -- --config-path ./bootstrap.yaml
+
+# List available Envoy flags.
+getenvoy run VERSION -- --help
+
+
+Flags:
+  -h, --help   help for run
+
+Global Flags:
+      --home-dir string   GetEnvoy home directory (location of downloaded artifacts, caches, etc)