Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
KirilKabakchiev committed Oct 10, 2019
1 parent 5121b38 commit cfcd2c4
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 45 deletions.
4 changes: 0 additions & 4 deletions internal/cmd/broker/delete_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ package broker
import (
"fmt"
"io"
"net/http"
"strings"

"github.com/Peripli/service-manager-cli/internal/output"
"github.com/Peripli/service-manager-cli/pkg/errors"

"github.com/Peripli/service-manager-cli/internal/util"

"github.com/spf13/cobra"

Expand Down
7 changes: 3 additions & 4 deletions internal/cmd/label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"errors"
"testing"

"io/ioutil"
"net/http"

"github.com/Peripli/service-manager-cli/internal/cmd"
"github.com/Peripli/service-manager-cli/pkg/smclient/smclientfakes"
"github.com/Peripli/service-manager-cli/pkg/types"
Expand All @@ -13,14 +16,10 @@ import (
"github.com/Peripli/service-manager/pkg/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"net/http"
"testing"
)

func TestLabelCmd(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "")
}

var _ = Describe("Label Command test", func() {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/offering/marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (m *MarketplaceCmd) Prepare(prepare cmd.PrepareFunc) *cobra.Command {

cmd.AddFormatFlag(result.Flags())
result.Flags().StringVarP(&m.offering, "service", "s", "", "Plan details for a single service offering")
cmd.AddCommonQueryFlag(result.Flags(), &m.Parameters)

return result
}
17 changes: 16 additions & 1 deletion internal/cmd/offering/marketplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestMarketplaceCmd(t *testing.T) {
}

var _ = Describe("Marketplace command test", func() {

var client *smclientfakes.FakeClient
var command *MarketplaceCmd
var buffer *bytes.Buffer
Expand Down Expand Up @@ -104,6 +103,22 @@ var _ = Describe("Marketplace command test", func() {
})
})

Context("when generic parameter is used", func() {
It("should pass it to SM", func() {
result := &types.Marketplace{ServiceOfferings: []types.ServiceOffering{noPlanOffering}}
client.MarketplaceReturns(result, nil)
param := "parameterKey=parameterValue"
err := executeWithArgs([]string{"--param", param})
Expect(err).ShouldNot(HaveOccurred())

args := client.MarketplaceArgsForCall(0)

Expect(args.GeneralParams).To(ConsistOf(param))
Expect(args.FieldQuery).To(BeEmpty())
Expect(args.LabelQuery).To(BeEmpty())
})
})

Context("when service flag is used", func() {
It("should list empty plans list when no plans provided", func() {
result := &types.Marketplace{ServiceOfferings: []types.ServiceOffering{noPlanOffering}}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/plan/list_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (lp *ListPlansCmd) Prepare(prepare cmd.PrepareFunc) *cobra.Command {

cmd.AddFormatFlag(result.Flags())
cmd.AddQueryingFlags(result.Flags(), &lp.Parameters)
cmd.AddCommonQueryFlag(result.Flags(), &lp.Parameters)

return result
}
23 changes: 20 additions & 3 deletions internal/cmd/plan/list_plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"bytes"
"encoding/json"
"errors"
"testing"

"github.com/Peripli/service-manager-cli/internal/cmd"
"github.com/Peripli/service-manager-cli/pkg/smclient/smclientfakes"
"github.com/Peripli/service-manager-cli/pkg/types"
"gopkg.in/yaml.v2"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -100,12 +101,28 @@ var _ = Describe("List plans command test", func() {
})
})

Context("when generic parameter is used", func() {
It("should pass it to SM", func() {
result := &types.ServicePlans{ServicePlans: []types.ServicePlan{plan1}}
client.ListPlansReturns(result, nil)
param := "parameterKey=parameterValue"
err := executeWithArgs([]string{"--param", param})
Expect(err).ShouldNot(HaveOccurred())

args := client.ListPlansArgsForCall(0)

Expect(args.GeneralParams).To(ConsistOf(param))
Expect(args.FieldQuery).To(BeEmpty())
Expect(args.LabelQuery).To(BeEmpty())
})
})

Context("when field query flag is used", func() {
It("should pass it to SM", func() {
result := &types.ServicePlans{ServicePlans: []types.ServicePlan{plan1}}
client.ListPlansReturns(result, nil)
param := "name = plan1"
err := executeWithArgs([]string{"-f", param})
err := executeWithArgs([]string{"--field-query", param})

args := client.ListPlansArgsForCall(0)

Expand All @@ -120,7 +137,7 @@ var _ = Describe("List plans command test", func() {
result := &types.ServicePlans{ServicePlans: []types.ServicePlan{plan1}}
client.ListPlansReturns(result, nil)
param := "test = false"
err := executeWithArgs([]string{"-l", param})
err := executeWithArgs([]string{"--label-query", param})

args := client.ListPlansArgsForCall(0)

Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/platform/delete_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package platform
import (
"fmt"
"io"
"net/http"
"strings"

"github.com/Peripli/service-manager-cli/internal/output"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (dpc *DeletePlatformCmd) Validate(args []string) error {
func (dpc *DeletePlatformCmd) Run() error {
dpc.Parameters.FieldQuery = append(dpc.Parameters.FieldQuery, fmt.Sprintf("name = %s", dpc.name))

if err := dpc.Client.DeletePlatforms(&dpc.Parameters); err != nil {
if err := dpc.Client.DeletePlatforms(&dpc.Parameters); err != nil {
if strings.Contains(err.Error(), "StatusCode: 404") {
output.PrintMessage(dpc.Output, "Platform(s) not found.\n")
return nil
Expand Down
16 changes: 6 additions & 10 deletions internal/cmd/visibility/delete_visibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package visibility
import (
"fmt"
"io"
"net/http"

"github.com/Peripli/service-manager-cli/pkg/errors"
"strings"

"github.com/Peripli/service-manager-cli/internal/cmd"
"github.com/Peripli/service-manager-cli/internal/output"
Expand Down Expand Up @@ -58,17 +56,15 @@ func (dv *DeleteVisibilityCmd) Validate(args []string) error {
func (dv *DeleteVisibilityCmd) Run() error {
dv.Parameters.FieldQuery = append(dv.Parameters.FieldQuery, fmt.Sprintf("id = %s", dv.id))

err := dv.Client.DeleteVisibilities(&dv.Parameters)

if respErr, ok := err.(errors.ResponseError); ok && respErr.StatusCode == http.StatusNotFound {
output.PrintMessage(dv.Output, "Visibility not found.\n")
return nil
} else if err != nil {
if err := dv.Client.DeleteVisibilities(&dv.Parameters); err != nil {
if strings.Contains(err.Error(), "StatusCode: 404") {
output.PrintMessage(dv.Output, "Visibility not found.\n")
return nil
}
output.PrintMessage(dv.Output, "Could not delete visibility(s). Reason: ")
return err
}
output.PrintMessage(dv.Output, "Visibility successfully deleted.\n")

return nil
}

Expand Down
5 changes: 2 additions & 3 deletions internal/cmd/visibility/delete_visibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package visibility

import (
"bytes"

"io/ioutil"
"net/http"
"testing"

Expand All @@ -10,9 +12,6 @@ import (
"github.com/Peripli/service-manager/pkg/util"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"net/http"
"testing"
)

func TestDeleteVisibilityCmd(t *testing.T) {
Expand Down
13 changes: 6 additions & 7 deletions pkg/smclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"bytes"
"context"
"encoding/json"
"github.com/Peripli/service-manager/pkg/util"
"fmt"
"io"
"net/http"

"github.com/Peripli/service-manager/pkg/util"

"github.com/Peripli/service-manager/pkg/web"

"github.com/Peripli/service-manager-cli/pkg/auth/oidc"
Expand Down Expand Up @@ -57,8 +58,6 @@ type Client interface {
UpdateVisibility(string, *types.Visibility, *query.Parameters) (*types.Visibility, error)
DeleteVisibilities(*query.Parameters) error

ListOfferings(*query.Parameters) (*types.ServiceOfferings, error)

Label(string, string, *types.LabelChanges, *query.Parameters) error

Marketplace(*query.Parameters) (*types.Marketplace, error)
Expand Down Expand Up @@ -227,7 +226,7 @@ func (client *serviceManagerClient) Marketplace(q *query.Parameters) (*types.Mar
}
for i, so := range marketplace.ServiceOfferings {
plans := &types.ServicePlansForOffering{}
err := client.list(&plans.ServicePlans, web.ServicePlansURL,&query.Parameters{
err := client.list(&plans.ServicePlans, web.ServicePlansURL, &query.Parameters{
FieldQuery: []string{fmt.Sprintf("service_offering_id = %s", so.ID)},
GeneralParams: q.GeneralParams,
})
Expand All @@ -237,7 +236,7 @@ func (client *serviceManagerClient) Marketplace(q *query.Parameters) (*types.Mar
marketplace.ServiceOfferings[i].Plans = plans.ServicePlans

broker := &types.Broker{}
err = client.list(broker, web.ServiceBrokersURL+"/"+so.BrokerID, &query.Parameters{
err = client.get(broker, web.ServiceBrokersURL+"/"+so.BrokerID, &query.Parameters{
GeneralParams: q.GeneralParams,
})
if err != nil {
Expand All @@ -250,12 +249,12 @@ func (client *serviceManagerClient) Marketplace(q *query.Parameters) (*types.Mar
}

func (client *serviceManagerClient) list(result interface{}, url string, q *query.Parameters) error {
fullURL := httputil.NormalizeURL(client.config.URL) + path
fullURL := httputil.NormalizeURL(client.config.URL) + buildURL(url, q)
return util.ListAll(context.Background(), client.httpClient.Do, fullURL, result)
}

func (client *serviceManagerClient) get(result interface{}, url string, q *query.Parameters) error {
resp, err := client.Call(http.MethodGet, path, nil, q)
resp, err := client.Call(http.MethodGet, url, nil, q)
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/smclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type HandlerDetails struct {
ResponseStatusCode int
}

func TestSmClient(t *testing.T) {
func TestSMClient(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "")
}
Expand Down Expand Up @@ -119,7 +119,7 @@ var _ = Describe("Service Manager Client test", func() {
}

verifyErrorMsg := func(errorMsg, path string, body []byte, statusCode int) {
Expect(errorMsg).To(ContainSubstring(smServer.URL + path))
Expect(errorMsg).To(ContainSubstring(buildURL(smServer.URL+path, params)))
Expect(errorMsg).To(ContainSubstring(string(body)))
Expect(errorMsg).To(ContainSubstring(fmt.Sprintf("StatusCode: %d", statusCode)))
}
Expand Down Expand Up @@ -668,7 +668,7 @@ var _ = Describe("Service Manager Client test", func() {
}
})
It("should return all with plans and broker name populated", func() {
result, err := client.Marketplace(nil)
result, err := client.Marketplace(params)
Expect(err).ShouldNot(HaveOccurred())
Expect(result.ServiceOfferings).To(HaveLen(1))
Expect(result.ServiceOfferings[0]).To(Equal(*resultOffering))
Expand All @@ -685,7 +685,7 @@ var _ = Describe("Service Manager Client test", func() {
}
})
It("should return empty array", func() {
result, err := client.Marketplace(nil)
result, err := client.Marketplace(params)
Expect(err).ShouldNot(HaveOccurred())
Expect(result.ServiceOfferings).To(HaveLen(0))
})
Expand All @@ -698,7 +698,7 @@ var _ = Describe("Service Manager Client test", func() {
}
})
It("should handle status code != 200", func() {
_, err := client.Marketplace(nil)
_, err := client.Marketplace(params)
Expect(err).Should(HaveOccurred())
verifyErrorMsg(err.Error(), handlerDetails[0].Path, handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
})
Expand All @@ -711,7 +711,7 @@ var _ = Describe("Service Manager Client test", func() {
}
})
It("should handle status code > 299", func() {
_, err := client.Marketplace(nil)
_, err := client.Marketplace(params)
Expect(err).Should(HaveOccurred())
verifyErrorMsg(err.Error(), handlerDetails[0].Path, handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
})
Expand Down Expand Up @@ -763,7 +763,7 @@ var _ = Describe("Service Manager Client test", func() {
params.FieldQuery = append(params.FieldQuery, "id = id")
err := client.DeleteBrokers(params)
Expect(err).Should(HaveOccurred())
verifyErrorMsg(err.Error(), handlerDetails[0].Path+"id", handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
verifyErrorMsg(err.Error(), handlerDetails[0].Path, handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
})
})
})
Expand Down Expand Up @@ -796,7 +796,7 @@ var _ = Describe("Service Manager Client test", func() {
params.FieldQuery = append(params.FieldQuery, "id = id")
err := client.DeletePlatforms(params)
Expect(err).Should(HaveOccurred())
verifyErrorMsg(err.Error(), handlerDetails[0].Path+"id", handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
verifyErrorMsg(err.Error(), handlerDetails[0].Path, handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
})
})

Expand All @@ -812,7 +812,7 @@ var _ = Describe("Service Manager Client test", func() {
params.FieldQuery = append(params.FieldQuery, "id = id")
err := client.DeletePlatforms(params)
Expect(err).Should(HaveOccurred())
verifyErrorMsg(err.Error(), handlerDetails[0].Path+"id", handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
verifyErrorMsg(err.Error(), handlerDetails[0].Path, handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
})
})
})
Expand Down Expand Up @@ -845,7 +845,7 @@ var _ = Describe("Service Manager Client test", func() {
params.FieldQuery = append(params.FieldQuery, "id = id")
err := client.DeleteVisibilities(params)
Expect(err).Should(HaveOccurred())
verifyErrorMsg(err.Error(), handlerDetails[0].Path+"id", handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
verifyErrorMsg(err.Error(), handlerDetails[0].Path, handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
})
})

Expand All @@ -861,7 +861,7 @@ var _ = Describe("Service Manager Client test", func() {
params.FieldQuery = append(params.FieldQuery, "id = id")
err := client.DeleteVisibilities(params)
Expect(err).Should(HaveOccurred())
verifyErrorMsg(err.Error(), handlerDetails[0].Path+"id", handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
verifyErrorMsg(err.Error(), handlerDetails[0].Path, handlerDetails[0].ResponseBody, handlerDetails[0].ResponseStatusCode)
})
})
})
Expand Down
Loading

0 comments on commit cfcd2c4

Please sign in to comment.