diff --git a/cmd/bindings/bindings.go b/cmd/bindings/bindings.go index 4936df7..81a2442 100644 --- a/cmd/bindings/bindings.go +++ b/cmd/bindings/bindings.go @@ -98,10 +98,11 @@ func cmdBindingsList(b *bindings, printf shared.FormatFn) *cobra.Command { func cmdBindingsAdd(b *bindings, printf shared.FormatFn) *cobra.Command { c := &cobra.Command{ - Use: "add [target name] [product name]", - Short: "Add Remote Target binding to Apigee Product", - Long: "Add Remote Target binding to Apigee Product", - Args: cobra.ExactArgs(2), + Deprecated: "please transition to APIs or UI.", + Use: "add [target name] [product name]", + Short: "Add Remote Target binding to Apigee Product", + Long: "Add Remote Target binding to Apigee Product", + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { targetName := args[0] @@ -128,10 +129,11 @@ func cmdBindingsAdd(b *bindings, printf shared.FormatFn) *cobra.Command { func cmdBindingsRemove(b *bindings, printf shared.FormatFn) *cobra.Command { c := &cobra.Command{ - Use: "remove [target name] [product name]", - Short: "Remove target binding from Apigee Product", - Long: "Remove target binding from Apigee Product", - Args: cobra.ExactArgs(2), + Deprecated: "please transition to APIs or UI.", + Use: "remove [target name] [product name]", + Short: "Remove target binding from Apigee Product", + Long: "Remove target binding from Apigee Product", + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { targetName := args[0] @@ -285,14 +287,7 @@ func (b *bindings) cmdList(productName string, printf shared.FormatFn) error { func printProducts(products []product.APIProduct, printf shared.FormatFn) error { var bound, unbound []product.APIProduct for _, p := range products { - // server returns empty scopes as array with a single empty string, remove for consistency - if len(p.Scopes) == 1 && p.Scopes[0] == "" { - p.Scopes = []string{} - } - // server may return empty quota field as "null" - if p.QuotaLimit == "null" { - p.QuotaLimit = "" - } + p.Targets = p.GetBoundTargets() if len(p.Targets) == 0 { unbound = append(unbound, p) diff --git a/cmd/bindings/bindings_test.go b/cmd/bindings/bindings_test.go index 2e909a8..0fe678a 100644 --- a/cmd/bindings/bindings_test.go +++ b/cmd/bindings/bindings_test.go @@ -45,7 +45,6 @@ func TestBindingListOPDK(t *testing.T) { var flags []string var rootCmd *cobra.Command var rootArgs *shared.RootArgs - var wants []string flags = []string{"bindings", "list", "--opdk", "--runtime", ts.URL, "-o", "/org/", "-e", "/env/", "-u", "/username/", "-p", "password"} @@ -55,40 +54,34 @@ func TestBindingListOPDK(t *testing.T) { if err = rootCmd.Execute(); err != nil { t.Errorf("want no error, got: %v", err) } - wants = []string{ - "\nAPI Products\n============", - "\nBound\n-----", - "\n", - "/product0/", - ":", - "\n Target bindings:", - "\n ", - "/target/", - "\n Paths:", - "\n", - "/product2/", - ":", - "\n Target bindings:", - "\n ", - "/target/", - "\n Paths:", - "\n", - "/product4/", - ":", - "\n Target bindings:", - "\n ", - "/target/", - "\n Paths:", - "\n\nUnbound\n-------", - "\n", - "/product/", - ":", - "\n", - "/product1/", - ":", - "\n", - } - print.Check(t, wants) + want := ` + API Products + ============ + Bound + ----- + /product0/: + Target bindings: + /target/ + Paths: + /product2/: + Target bindings: + /target/ + Paths: + /product4/: + Target bindings: + /target/ + Paths: + /productOG/: + Target bindings: + /target/ + Paths: + + Unbound + ------- + /product/: + /product1/: + ` + print.CheckString(t, want) flags = []string{"bindings", "list", "/product2/", "--opdk", "--runtime", ts.URL, "-o", "/org/", "-e", "/env/", "-u", "/username/", "-p", "password"} @@ -98,19 +91,17 @@ func TestBindingListOPDK(t *testing.T) { if err = rootCmd.Execute(); err != nil { t.Errorf("want no error, got: %v", err) } - wants = []string{ - "\nAPI Products\n============", - "\nBound\n-----", - "\n", - "/product2/", - ":", - "\n Target bindings:", - "\n ", - "/target/", - "\n Paths:", - "\n", - } - print.Check(t, wants) + want = ` + API Products + ============ + Bound + ----- + /product2/: + Target bindings: + /target/ + Paths: +` + print.CheckString(t, want) } func TestBindingAddOPDK(t *testing.T) { @@ -231,6 +222,8 @@ func TestBindingVerifyAll(t *testing.T) { " app /app1/ associated with product /product2/ is verified", "Verifying apps associated with product /product0/:", " app /app0/ associated with product /product0/ is verified", + "Verifying apps associated with product /productOG/:", + " app /appOG/ associated with product /productOG/ is verified", "No app is found associated with product /product4/.", } print.Check(t, wants) @@ -294,6 +287,25 @@ func productTestServer(t *testing.T) *httptest.Server { QuotaLimit: "null", Scopes: []string{""}, }, + { + Name: "/productOG/", + Attributes: []product.Attribute{}, + QuotaLimit: "", + Scopes: []string{""}, + OperationGroup: &product.OperationGroup{ + OperationConfigs: []product.OperationConfig{ + { + APISource: "/target/", + Operations: []product.Operation{ + { + Resource: "/", + Methods: []string{"GET"}, + }, + }, + }, + }, + }, + }, { Name: "/product4/", Attributes: []product.Attribute{ @@ -381,6 +393,28 @@ func productTestServer(t *testing.T) *httptest.Server { }, }, }, + { + AppID: "OG", + Name: "/appOG/", + Credentials: []apigee.Credential{ + { + APIProducts: []apigee.APIProductRef{ + { + Name: "remote-service", + Status: "approved", + }, + }, + }, + { + APIProducts: []apigee.APIProductRef{ + { + Name: "/productOG/", + Status: "approved", + }, + }, + }, + }, + }, }, } diff --git a/go.mod b/go.mod index 2d2e81d..24cc47a 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ go 1.15 require ( github.com/apigee/apigee-remote-service-envoy v1.2.1-0.20201020222450-69c583ebd596 - github.com/apigee/apigee-remote-service-golib v1.2.1-0.20201020221247-3391bb81c8bf + github.com/apigee/apigee-remote-service-golib v1.2.1-0.20201027165703-a8426370e0a0 github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d github.com/lestrrat-go/jwx v1.0.4 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index b6de7d2..8edef8c 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,9 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apigee/apigee-remote-service-envoy v1.2.1-0.20201020222450-69c583ebd596 h1:uMqwGQDEK+4fFatXor8w3nNVhhuezoaQWDKd+B/mmg4= github.com/apigee/apigee-remote-service-envoy v1.2.1-0.20201020222450-69c583ebd596/go.mod h1:HfVZthQtN6eSlSwQ2Y16c5d8iVVpvH2EXltW+dGeMq4= -github.com/apigee/apigee-remote-service-golib v1.2.1-0.20201020221247-3391bb81c8bf h1:7vJnKbSvSum5bxfj00XwhOwWg16eTzxMa5cDm4yGQZs= github.com/apigee/apigee-remote-service-golib v1.2.1-0.20201020221247-3391bb81c8bf/go.mod h1:J/2GDsnbdp7dyVWCTlmVs6+Tz7VWIo1F9yoZvBhvwe0= +github.com/apigee/apigee-remote-service-golib v1.2.1-0.20201027165703-a8426370e0a0 h1:vbVToL4aQlSD6eWVZBwQVlz3Gx54Be9GhvttFjsEWxY= +github.com/apigee/apigee-remote-service-golib v1.2.1-0.20201027165703-a8426370e0a0/go.mod h1:J/2GDsnbdp7dyVWCTlmVs6+Tz7VWIo1F9yoZvBhvwe0= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= diff --git a/testutil/test_print.go b/testutil/test_print.go index fff494b..6bfe0ef 100644 --- a/testutil/test_print.go +++ b/testutil/test_print.go @@ -16,6 +16,7 @@ package testutil import ( "fmt" + "regexp" "strings" "testing" ) @@ -78,3 +79,26 @@ func (tp *TestPrint) CheckPrefix(t *testing.T, want []string) { tp.Prints = nil } + +// CheckString is for checking test output +func (tp *TestPrint) CheckString(t *testing.T, want string) { + strippedWant := stripSymbols(want) + + var builder strings.Builder + for _, p := range tp.Prints { + builder.WriteString(p) + } + got := builder.String() + strippedGot := stripSymbols(got) + + if strippedWant != strippedGot { + t.Errorf("want: '%s',\n got: '%s'", want, got) + } + + tp.Prints = nil +} + +func stripSymbols(str string) string { + symbols := regexp.MustCompile(`\s+`) + return symbols.ReplaceAllString(str, " ") +}