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

update bindings commands for operations #88

Merged
merged 2 commits into from
Oct 27, 2020
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
27 changes: 11 additions & 16 deletions cmd/bindings/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
130 changes: 82 additions & 48 deletions cmd/bindings/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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"}
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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",
},
},
},
},
},
},
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
24 changes: 24 additions & 0 deletions testutil/test_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package testutil

import (
"fmt"
"regexp"
"strings"
"testing"
)
Expand Down Expand Up @@ -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, " ")
}