Skip to content

Commit

Permalink
Move the lib/ to public pkg/ packages
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Jun 20, 2024
1 parent 51a0693 commit 671e679
Show file tree
Hide file tree
Showing 59 changed files with 140 additions and 188 deletions.
14 changes: 6 additions & 8 deletions cmd/kn/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@ import (
"strings"
"testing"

"knative.dev/client/pkg/config"
pluginpkg "knative.dev/client/pkg/plugin"

"github.com/spf13/cobra"
"gotest.tools/v3/assert"

"knative.dev/client/lib/test"
"knative.dev/client/pkg/config"
pluginpkg "knative.dev/client/pkg/plugin"
"knative.dev/client/pkg/root"
"knative.dev/client/pkg/util"
"knative.dev/client/pkg/util/test"
)

func TestValidatePlugin(t *testing.T) {

// Build up simple command hierarchy
root := cobra.Command{}
rootCmd := cobra.Command{}
one := &cobra.Command{Use: "one"}
one.AddCommand(&cobra.Command{Use: "eins"}, &cobra.Command{Use: "zwei"})
two := &cobra.Command{Use: "two"}
root.AddCommand(one, two)
rootCmd.AddCommand(one, two)

data := []struct {
givenPluginCommandParts []string
Expand Down Expand Up @@ -84,7 +82,7 @@ func TestValidatePlugin(t *testing.T) {

for i, d := range data {
step := fmt.Sprintf("Check %d", i)
err := validatePlugin(&root, commandPartsOnlyPlugin(d.givenPluginCommandParts))
err := validatePlugin(&rootCmd, commandPartsOnlyPlugin(d.givenPluginCommandParts))
if len(d.expectedErrors) == 0 {
assert.NilError(t, err, step)
} else {
Expand Down
7 changes: 3 additions & 4 deletions pkg/commands/completion/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ package completion
import (
"testing"

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

"github.com/spf13/cobra"
"gotest.tools/v3/assert"
"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/util"
"knative.dev/client/pkg/util/test"
)

func TestCompletionUsage(t *testing.T) {
Expand Down
6 changes: 2 additions & 4 deletions pkg/commands/namespaced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import (
"path/filepath"
"testing"

"knative.dev/client/lib/test"

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

"github.com/spf13/cobra"
"gotest.tools/v3/assert"
"k8s.io/client-go/tools/clientcmd"
"knative.dev/client/pkg/util/test"
)

// testCommandGenerator generates a test cobra command
Expand Down
108 changes: 53 additions & 55 deletions pkg/commands/service/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import (
"encoding/json"
"testing"

"knative.dev/client/pkg/serving"

"gotest.tools/v3/assert"

v1 "k8s.io/api/core/v1"
libtest "knative.dev/client/lib/test"
clientv1alpha1 "knative.dev/client/pkg/apis/client/v1alpha1"
"knative.dev/client/pkg/serving"
knclient "knative.dev/client/pkg/serving/v1"
"knative.dev/client/pkg/util/mock"
"knative.dev/client/pkg/util/test"
"knative.dev/pkg/ptr"
apiserving "knative.dev/serving/pkg/apis/serving"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
Expand Down Expand Up @@ -63,14 +61,14 @@ func TestServiceExportError(t *testing.T) {
func TestServiceExport(t *testing.T) {

for _, tc := range []testCase{
{latestSvc: libtest.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()))},
{latestSvc: libtest.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), servingtest.WithEnv(v1.EnvVar{Name: "a", Value: "mouse"}))},
{latestSvc: libtest.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), libtest.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v2"}))},
{latestSvc: libtest.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), servingtest.WithServiceLabel("a", "mouse"), servingtest.WithServiceAnnotation("a", "mouse"))},
{latestSvc: libtest.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), servingtest.WithVolume("secretName", "/mountpath", volumeSource("secretName")))},
{latestSvc: test.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()))},
{latestSvc: test.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), servingtest.WithEnv(v1.EnvVar{Name: "a", Value: "mouse"}))},
{latestSvc: test.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), test.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v2"}))},
{latestSvc: test.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), servingtest.WithServiceLabel("a", "mouse"), servingtest.WithServiceAnnotation("a", "mouse"))},
{latestSvc: test.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()), servingtest.WithVolume("secretName", "/mountpath", volumeSource("secretName")))},
} {
exportServiceTestForReplay(t, &tc)
tc.expectedKNExport = libtest.BuildKNExportWithOptions()
tc.expectedKNExport = test.BuildKNExportWithOptions()
exportServiceTest(t, &tc, true)
//test default
exportServiceTest(t, &tc, false)
Expand Down Expand Up @@ -108,125 +106,125 @@ func exportServiceTest(t *testing.T, tc *testCase, addMode bool) {
func TestServiceExportwithMultipleRevisions(t *testing.T) {
for _, tc := range []testCase{{
name: "test 2 revisions with traffic split",
latestSvc: libtest.BuildServiceWithOptions(
latestSvc: test.BuildServiceWithOptions(
"foo", servingtest.WithConfigSpec(buildConfiguration()),
libtest.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v2"}),
libtest.WithTrafficSpec([]string{"foo-rev-1", "latest"}, []int{50, 50}, []string{"", ""}),
test.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v2"}),
test.WithTrafficSpec([]string{"foo-rev-1", "latest"}, []int{50, 50}, []string{"", ""}),
),
expectedSvcList: libtest.BuildServiceListWithOptions(
libtest.WithService(libtest.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()),
libtest.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v1"}),
expectedSvcList: test.BuildServiceListWithOptions(
test.WithService(test.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()),
test.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v1"}),
servingtest.WithBYORevisionName("foo-rev-1"),
)),
libtest.WithService(libtest.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()),
libtest.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v2"}),
libtest.WithTrafficSpec([]string{"foo-rev-1", "latest"}, []int{50, 50}, []string{"", ""}),
test.WithService(test.BuildServiceWithOptions("foo", servingtest.WithConfigSpec(buildConfiguration()),
test.WithRevisionAnnotations(map[string]string{"client.knative.dev/user-image": "busybox:v2"}),
test.WithTrafficSpec([]string{"foo-rev-1", "latest"}, []int{50, 50}, []string{"", ""}),
)),
),
revisionList: libtest.BuildRevisionListWithOptions(
libtest.WithRevision(*(libtest.BuildRevision("foo-rev-1",
revisionList: test.BuildRevisionListWithOptions(
test.WithRevision(*(test.BuildRevision("foo-rev-1",
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "1"),
servingtest.WithRevisionAnn("client.knative.dev/user-image", "busybox:v1"),
servingtest.WithRevisionAnn("serving.knative.dev/lastPinned", "1111132"),
servingtest.WithRevisionAnn(serving.UpdateTimestampAnnotationKey, "now"),
))),
libtest.WithRevision(*(libtest.BuildRevision("foo-rev-2",
test.WithRevision(*(test.BuildRevision("foo-rev-2",
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "1"),
servingtest.WithRevisionAnn("client.knative.dev/user-image", "busybox:v2"),
servingtest.WithRevisionAnn(serving.UpdateTimestampAnnotationKey, "now"),
))),
),
expectedKNExport: libtest.BuildKNExportWithOptions(
libtest.WithKNRevision(*(libtest.BuildRevision("foo-rev-1",
expectedKNExport: test.BuildKNExportWithOptions(
test.WithKNRevision(*(test.BuildRevision("foo-rev-1",
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "1"),
servingtest.WithRevisionAnn("client.knative.dev/user-image", "busybox:v1"),
))),
),
}, {
name: "test 2 revisions no traffic split",
latestSvc: libtest.BuildServiceWithOptions(
latestSvc: test.BuildServiceWithOptions(
"foo", servingtest.WithConfigSpec(buildConfiguration()),
libtest.WithTrafficSpec([]string{"latest"}, []int{100}, []string{""}),
test.WithTrafficSpec([]string{"latest"}, []int{100}, []string{""}),
),
expectedSvcList: libtest.BuildServiceListWithOptions(
libtest.WithService(libtest.BuildServiceWithOptions(
expectedSvcList: test.BuildServiceListWithOptions(
test.WithService(test.BuildServiceWithOptions(
"foo", servingtest.WithConfigSpec(buildConfiguration()),
libtest.WithTrafficSpec([]string{"latest"}, []int{100}, []string{""}),
test.WithTrafficSpec([]string{"latest"}, []int{100}, []string{""}),
)),
),
revisionList: libtest.BuildRevisionListWithOptions(
libtest.WithRevision(*(libtest.BuildRevision("foo-rev-1",
revisionList: test.BuildRevisionListWithOptions(
test.WithRevision(*(test.BuildRevision("foo-rev-1",
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "1"),
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
))),
libtest.WithRevision(*(libtest.BuildRevision("foo-rev-2",
test.WithRevision(*(test.BuildRevision("foo-rev-2",
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "2"),
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
))),
),
expectedKNExport: libtest.BuildKNExportWithOptions(),
expectedKNExport: test.BuildKNExportWithOptions(),
}, {
name: "test 3 active revisions with traffic split with no latest revision",
latestSvc: libtest.BuildServiceWithOptions(
latestSvc: test.BuildServiceWithOptions(
"foo", servingtest.WithConfigSpec(buildConfiguration()),
servingtest.WithEnv(v1.EnvVar{Name: "a", Value: "mouse"}),
servingtest.WithBYORevisionName("foo-rev-3"),
libtest.WithTrafficSpec([]string{"foo-rev-1", "foo-rev-2", "foo-rev-3"}, []int{25, 50, 25}, []string{"", "", ""}),
test.WithTrafficSpec([]string{"foo-rev-1", "foo-rev-2", "foo-rev-3"}, []int{25, 50, 25}, []string{"", "", ""}),
),
expectedSvcList: libtest.BuildServiceListWithOptions(
libtest.WithService(
libtest.BuildServiceWithOptions(
expectedSvcList: test.BuildServiceListWithOptions(
test.WithService(
test.BuildServiceWithOptions(
"foo", servingtest.WithConfigSpec(buildConfiguration()),
servingtest.WithEnv(v1.EnvVar{Name: "a", Value: "cat"}),
servingtest.WithBYORevisionName("foo-rev-1"),
),
),
libtest.WithService(
libtest.BuildServiceWithOptions(
test.WithService(
test.BuildServiceWithOptions(
"foo", servingtest.WithConfigSpec(buildConfiguration()),
servingtest.WithEnv(v1.EnvVar{Name: "a", Value: "dog"}),
servingtest.WithBYORevisionName("foo-rev-2"),
),
),
libtest.WithService(
libtest.BuildServiceWithOptions(
test.WithService(
test.BuildServiceWithOptions(
"foo", servingtest.WithConfigSpec(buildConfiguration()),
servingtest.WithEnv(v1.EnvVar{Name: "a", Value: "mouse"}),
servingtest.WithBYORevisionName("foo-rev-3"),
libtest.WithTrafficSpec([]string{"foo-rev-1", "foo-rev-2", "foo-rev-3"}, []int{25, 50, 25}, []string{"", "", ""}),
test.WithTrafficSpec([]string{"foo-rev-1", "foo-rev-2", "foo-rev-3"}, []int{25, 50, 25}, []string{"", "", ""}),
),
),
),
revisionList: libtest.BuildRevisionListWithOptions(
libtest.WithRevision(*(libtest.BuildRevision("foo-rev-1",
revisionList: test.BuildRevisionListWithOptions(
test.WithRevision(*(test.BuildRevision("foo-rev-1",
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "1"),
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
libtest.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "cat"}),
test.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "cat"}),
))),
libtest.WithRevision(*(libtest.BuildRevision("foo-rev-2",
test.WithRevision(*(test.BuildRevision("foo-rev-2",
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "2"),
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
libtest.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "dog"}),
test.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "dog"}),
))),
libtest.WithRevision(*(libtest.BuildRevision("foo-rev-3",
test.WithRevision(*(test.BuildRevision("foo-rev-3",
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "3"),
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
libtest.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "mouse"}),
test.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "mouse"}),
))),
),
expectedKNExport: libtest.BuildKNExportWithOptions(
libtest.WithKNRevision(*(libtest.BuildRevision("foo-rev-1",
expectedKNExport: test.BuildKNExportWithOptions(
test.WithKNRevision(*(test.BuildRevision("foo-rev-1",
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "1"),
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
libtest.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "cat"}),
test.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "cat"}),
))),
libtest.WithKNRevision(*(libtest.BuildRevision("foo-rev-2",
test.WithKNRevision(*(test.BuildRevision("foo-rev-2",
servingtest.WithRevisionLabel(apiserving.ConfigurationGenerationLabelKey, "2"),
servingtest.WithRevisionLabel(apiserving.ServiceLabelKey, "foo"),
libtest.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "dog"}),
test.WithRevisionEnv(v1.EnvVar{Name: "a", Value: "dog"}),
))),
),
}} {
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/source/apiserver/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"knative.dev/client/pkg/printers/describe"

"knative.dev/client/lib/printing"
"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/printers"
v1 "knative.dev/eventing/pkg/apis/sources/v1"
Expand Down Expand Up @@ -85,7 +85,7 @@ func NewAPIServerDescribeCommand(p *commands.KnParams) *cobra.Command {
return err
}

printing.DescribeSink(dw, "Sink", apiSource.Namespace, &apiSource.Spec.Sink)
describe.Sink(dw, "Sink", apiSource.Namespace, &apiSource.Spec.Sink)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/source/binding/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"knative.dev/client/pkg/printers/describe"
v1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/pkg/tracker"

"knative.dev/client/lib/printing"
"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/printers"
)
Expand Down Expand Up @@ -105,7 +105,7 @@ func NewBindingDescribeCommand(p *commands.KnParams) *cobra.Command {
func writeSinkBinding(dw printers.PrefixWriter, binding *v1.SinkBinding, printDetails bool) {
commands.WriteMetadata(dw, &binding.ObjectMeta, printDetails)
writeSubject(dw, binding.Namespace, &binding.Spec.Subject)
printing.DescribeSink(dw, "Sink", binding.Namespace, &binding.Spec.Sink)
describe.Sink(dw, "Sink", binding.Namespace, &binding.Spec.Sink)
if binding.Spec.CloudEventOverrides != nil && binding.Spec.CloudEventOverrides.Extensions != nil {
writeCeOverrides(dw, binding.Spec.CloudEventOverrides.Extensions)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/source/container/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (

"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"knative.dev/client/lib/printing"
"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/printers"
"knative.dev/client/pkg/printers/describe"
v1 "knative.dev/eventing/pkg/apis/sources/v1"
)

Expand Down Expand Up @@ -67,7 +67,7 @@ func NewContainerDescribeCommand(p *commands.KnParams) *cobra.Command {
return err
}

printing.DescribeSink(dw, "Sink", source.Namespace, &source.Spec.Sink)
describe.Sink(dw, "Sink", source.Namespace, &source.Spec.Sink)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/source/ping/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"knative.dev/client/pkg/printers/describe"

"knative.dev/client/lib/printing"
"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/printers"
clientsourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
Expand Down Expand Up @@ -85,7 +85,7 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
}

// Revisions summary info
printing.DescribeSink(dw, "Sink", pingSource.Namespace, &pingSource.Spec.Sink)
describe.Sink(dw, "Sink", pingSource.Namespace, &pingSource.Spec.Sink)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/subscription/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"fmt"

"github.com/spf13/cobra"
"knative.dev/client/pkg/printers/describe"

"k8s.io/cli-runtime/pkg/genericclioptions"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"

"knative.dev/client/lib/printing"
"knative.dev/client/pkg/commands"
knerrors "knative.dev/client/pkg/errors"
"knative.dev/client/pkg/printers"
Expand Down Expand Up @@ -103,9 +103,9 @@ func writeSubscription(dw printers.PrefixWriter, subscription *messagingv1.Subsc
commands.WriteMetadata(dw, &subscription.ObjectMeta, printDetails)
ctype := fmt.Sprintf("%s:%s (%s)", subscription.Spec.Channel.Kind, subscription.Spec.Channel.Name, subscription.Spec.Channel.APIVersion)
dw.WriteAttribute("Channel", ctype)
printing.DescribeSink(dw, "Subscriber", subscription.Namespace, subscription.Spec.Subscriber)
printing.DescribeSink(dw, "Reply", subscription.Namespace, subscription.Spec.Reply)
describe.Sink(dw, "Subscriber", subscription.Namespace, subscription.Spec.Subscriber)
describe.Sink(dw, "Reply", subscription.Namespace, subscription.Spec.Reply)
if subscription.Spec.DeepCopy().Delivery != nil {
printing.DescribeSink(dw, "DeadLetterSink", subscription.Namespace, subscription.Spec.Delivery.DeadLetterSink)
describe.Sink(dw, "DeadLetterSink", subscription.Namespace, subscription.Spec.Delivery.DeadLetterSink)
}
}
3 changes: 1 addition & 2 deletions pkg/commands/testing_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import (

"github.com/spf13/cobra"
"gotest.tools/v3/assert"

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

func TestCreateTestKnCommand(t *testing.T) {
Expand Down
Loading

0 comments on commit 671e679

Please sign in to comment.