Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move code being used by func from client #79

Merged
merged 2 commits into from
Jan 16, 2023
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
2 changes: 1 addition & 1 deletion pkg/kn-source-pkg/test/e2e/basic_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"gotest.tools/v3/assert"
"knative.dev/client-pkg/pkg/util"
"knative.dev/client-pkg/pkg/util/lib/test"
"knative.dev/client-pkg/pkg/util/test"
)

func TestBasicWorkflow(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn-source-pkg/test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package e2e

import (
"knative.dev/client-pkg/pkg/util/lib/test"
"knative.dev/client-pkg/pkg/util/test"
)

type E2ETest struct {
Expand Down
14 changes: 7 additions & 7 deletions pkg/kn-source-pkg/test/e2e/kn_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ import (
"strings"

homedir "github.com/mitchellh/go-homedir"
"knative.dev/client-pkg/pkg/util/lib/test"
test2 "knative.dev/client-pkg/pkg/util/test"
)

type knPlugin struct {
kn test.Kn
kn test2.Kn
pluginName string
pluginPath string
install bool
}

// Run the KnPlugin returning a KnRunResult
func (kp *knPlugin) Run(args ...string) test.KnRunResult {
func (kp *knPlugin) Run(args ...string) test2.KnRunResult {
if kp.install {
err := kp.Install()
if err != nil {
fmt.Printf("error installing kn plugin: %s\n", err.Error())
return test.KnRunResult{}
return test2.KnRunResult{}
}
defer kp.Uninstall()
}
return RunKnPlugin(kp.kn.Namespace(), kp.pluginName, args)
}

// Kn object to run `kn`
func (kp *knPlugin) Kn() test.Kn {
func (kp *knPlugin) Kn() test2.Kn {
return kp.kn
}

Expand Down Expand Up @@ -153,9 +153,9 @@ func pluginArgs(pluginName string) []string {
return pluginParts[1:]
}

func RunKnPlugin(namespace string, pluginName string, args []string) test.KnRunResult {
func RunKnPlugin(namespace string, pluginName string, args []string) test2.KnRunResult {
pluginArgs := pluginArgs(pluginName)
args = append(args, []string{"--namespace", namespace}...)
argsWithPlugin := append(pluginArgs, args...)
return test.RunKn(namespace, argsWithPlugin)
return test2.RunKn(namespace, argsWithPlugin)
}
2 changes: 1 addition & 1 deletion pkg/kn/commands/namespaced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"path/filepath"
"testing"

"knative.dev/client-pkg/pkg/util/lib/test"
"knative.dev/client-pkg/pkg/util/test"

"k8s.io/client-go/tools/clientcmd"

Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"testing"

"knative.dev/client-pkg/pkg/util/lib/test"
"knative.dev/client-pkg/pkg/util/test"

"gotest.tools/v3/assert"
"k8s.io/client-go/tools/clientcmd"
Expand Down
5 changes: 2 additions & 3 deletions pkg/kn/flags/podspec_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ import (
"testing"

"k8s.io/apimachinery/pkg/util/intstr"

"k8s.io/apimachinery/pkg/api/resource"
"knative.dev/client-pkg/pkg/util/lib/test"
"knative.dev/client-pkg/pkg/util/test"

"gotest.tools/v3/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"knative.dev/client-pkg/pkg/util"
"knative.dev/pkg/ptr"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/serving/v1/gitops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"time"

"gotest.tools/v3/assert"
libtest "knative.dev/client-pkg/pkg/util/test"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
servingtest "knative.dev/serving/pkg/testing/v1"

libtest "knative.dev/client-pkg/pkg/util/lib/test"
"knative.dev/pkg/ptr"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
)
Expand Down
77 changes: 77 additions & 0 deletions pkg/util/test/capture_output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2020 The Knative Authors

// 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.

// OutputCapture allows to capture any text written to standard out or standard error
// which is especially useful during testing.
//
// Call it like:
//
// capture := CaptureOutput(t)
// doSomeActionThatWritesToStdOutAndStdErr()
// stdOut, stdErr := capture.Close()
//
// CaptureOutput() and capture.Close() should always come in pairs as Close() also
// restores the old streams
package test

import (
"io"
"os"
"testing"

"gotest.tools/v3/assert"
)

type OutputCapture struct {
outRead, outWrite *os.File
errorRead, errorWrite *os.File
t *testing.T

oldStdout *os.File
oldStderr *os.File
}

// CaptureOutput sets up standard our and standard error to capture any
// output which
func CaptureOutput(t *testing.T) OutputCapture {
ret := OutputCapture{
oldStdout: os.Stdout,
oldStderr: os.Stderr,
t: t,
}
var err error
ret.outRead, ret.outWrite, err = os.Pipe()
assert.NilError(t, err)
os.Stdout = ret.outWrite
ret.errorRead, ret.errorWrite, err = os.Pipe()
assert.NilError(t, err)
os.Stderr = ret.errorWrite
return ret
}

// Close return the output collected and restores the original standard out and error streams
// (i.e. those that were present before the call to CaptureOutput).
func (c OutputCapture) Close() (string, string) {
err := c.outWrite.Close()
assert.NilError(c.t, err)
err = c.errorWrite.Close()
assert.NilError(c.t, err)
outOutput, err := io.ReadAll(c.outRead)
assert.NilError(c.t, err)
errOutput, err := io.ReadAll(c.errorRead)
assert.NilError(c.t, err)
os.Stdout = c.oldStdout
os.Stderr = c.oldStderr
return string(outOutput), string(errOutput)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.