Skip to content

Commit

Permalink
Add sink flags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navidshaikh committed Sep 24, 2020
1 parent e7e18d1 commit 0faca61
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/kn/commands/flags/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package flags
import (
"testing"

"github.com/spf13/cobra"
"gotest.tools/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1"
Expand All @@ -33,6 +34,40 @@ type resolveCase struct {
errContents string
}

type sinkFlagAddTestCases struct {
flagName string
expectedFlagName string
expectedShortName string
}

func TestSinkFlagAdd(t *testing.T) {
cases := []*sinkFlagAddTestCases{
{
"",
"sink",
"s",
},
{
"subscriber",
"subscriber",
"",
},
}
for _, tc := range cases {
c := &cobra.Command{Use: "sinktest"}
sinkFlags := new(SinkFlags)
if tc.flagName == "" {
sinkFlags.Add(c)
assert.Equal(t, tc.expectedFlagName, c.Flag("sink").Name)
assert.Equal(t, tc.expectedShortName, c.Flag("sink").Shorthand)
} else {
sinkFlags.Add(c, tc.flagName)
assert.Equal(t, tc.expectedFlagName, c.Flag(tc.flagName).Name)
assert.Equal(t, tc.expectedShortName, c.Flag(tc.flagName).Shorthand)
}
}
}

func TestResolve(t *testing.T) {
targetExampleCom, err := apis.ParseURL("http://target.example.com")
mysvc := &servingv1.Service{
Expand Down

0 comments on commit 0faca61

Please sign in to comment.