-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Nicholas Seemiller <nseemiller@vmware.com>
- Loading branch information
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
.DS_Store | ||
/test/e2e/assets/simple-app/empty-dir | ||
dist/ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2020 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/google/go-containerregistry/pkg/logs" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
// DebugFlags indicates debugging | ||
type DebugFlags struct { | ||
Debug bool | ||
} | ||
|
||
// Set adds the debug flag to the command | ||
func (f *DebugFlags) Set(cmd *cobra.Command) { | ||
cmd.PersistentFlags().BoolVar(&f.Debug, "debug", false, "Enables debugging") | ||
} | ||
|
||
// ConfigureDebug set debug output to os.Stdout | ||
func (f *DebugFlags) ConfigureDebug() { | ||
if f.Debug { | ||
logs.Debug.SetOutput(os.Stderr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2020 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
|
||
"github.com/k14s/imgpkg/test/helpers" | ||
) | ||
|
||
func TestDebugDisabled(t *testing.T) { | ||
env := helpers.BuildEnv(t) | ||
imgpkg := helpers.Imgpkg{T: t, L: helpers.Logger{}, ImgpkgPath: env.ImgpkgPath} | ||
defer env.Cleanup() | ||
|
||
registry := helpers.NewFakeRegistry(t, &helpers.Logger{}) | ||
registry.Build() | ||
defer registry.ResetHandler() | ||
|
||
repo := registry.ReferenceOnTestServer("nothing") | ||
out := bytes.NewBufferString("") | ||
_, err := imgpkg.RunWithOpts([]string{"pull", "--tty", "-i", repo, "-o", "/dev/null"}, helpers.RunOpts{ | ||
AllowError: true, | ||
StderrWriter: out, | ||
StdoutWriter: out, | ||
}) | ||
|
||
assert.Error(t, err) | ||
assert.Regexp(t, `^imgpkg: Error: Fetching image: | ||
\s+GET http://127.0.0.1:[0-9]+/v2/nothing/manifests/latest: | ||
\s+NAME_UNKNOWN: | ||
\s+Unknown name`, out.String()) | ||
} | ||
|
||
func TestDebugEnabled(t *testing.T) { | ||
env := helpers.BuildEnv(t) | ||
imgpkg := helpers.Imgpkg{T: t, L: helpers.Logger{}, ImgpkgPath: env.ImgpkgPath} | ||
defer env.Cleanup() | ||
|
||
registry := helpers.NewFakeRegistry(t, &helpers.Logger{}) | ||
registry.Build() | ||
defer registry.ResetHandler() | ||
|
||
repo := registry.ReferenceOnTestServer("nothing") | ||
out := bytes.NewBufferString("") | ||
_, err := imgpkg.RunWithOpts([]string{"pull", "--tty", "-i", repo, "--debug", "-o", "/dev/null"}, helpers.RunOpts{ | ||
AllowError: true, | ||
StderrWriter: out, | ||
StdoutWriter: out, | ||
}) | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, out.String(), "Accept-Encoding") | ||
} |