From 7a1034096f3906a8a326572134268523dba8c76f Mon Sep 17 00:00:00 2001 From: Robert Scherbarth Date: Wed, 8 Aug 2018 17:50:18 +0200 Subject: [PATCH] Add a DashboardURL row to svcat describe instances (#2262) --- cmd/svcat/output/instance.go | 13 ++++++++ cmd/svcat/output/instance_test.go | 55 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 cmd/svcat/output/instance_test.go diff --git a/cmd/svcat/output/instance.go b/cmd/svcat/output/instance.go index bd881f372e9..7077bac1be0 100644 --- a/cmd/svcat/output/instance.go +++ b/cmd/svcat/output/instance.go @@ -21,6 +21,7 @@ import ( "io" "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1" + "github.com/olekukonko/tablewriter" ) func getInstanceStatusCondition(status v1beta1.ServiceInstanceStatus) v1beta1.ServiceInstanceCondition { @@ -40,6 +41,15 @@ func getInstanceStatusShort(status v1beta1.ServiceInstanceStatus) string { return formatStatusShort(string(lastCond.Type), lastCond.Status, lastCond.Reason) } +func appendInstanceDashboardURL(status v1beta1.ServiceInstanceStatus, table *tablewriter.Table) { + if status.DashboardURL != nil { + dashboardURL := *status.DashboardURL + table.AppendBulk([][]string{ + {"DashboardURL:", dashboardURL}, + }) + } +} + func writeInstanceListTable(w io.Writer, instanceList *v1beta1.ServiceInstanceList) { t := NewListTable(w) t.SetHeader([]string{ @@ -133,6 +143,9 @@ func WriteInstanceDetails(w io.Writer, instance *v1beta1.ServiceInstance) { {"Name:", instance.Name}, {"Namespace:", instance.Namespace}, {"Status:", getInstanceStatusFull(instance.Status)}, + }) + appendInstanceDashboardURL(instance.Status, t) + t.AppendBulk([][]string{ {"Class:", instance.Spec.GetSpecifiedClusterServiceClass()}, {"Plan:", instance.Spec.GetSpecifiedClusterServicePlan()}, }) diff --git a/cmd/svcat/output/instance_test.go b/cmd/svcat/output/instance_test.go new file mode 100644 index 00000000000..17ea60d14f7 --- /dev/null +++ b/cmd/svcat/output/instance_test.go @@ -0,0 +1,55 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package output + +import ( + "strings" + "testing" + + "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1" + "github.com/olekukonko/tablewriter" +) + +func Test_appendInstanceDashboardURL(t *testing.T) { + dashboardURL := "grafana.example.com" + table := &tablewriter.Table{} + + tests := []struct { + name string + status v1beta1.ServiceInstanceStatus + table *tablewriter.Table + expectedString string + }{ + {"dashboardURLOK", v1beta1.ServiceInstanceStatus{ + DashboardURL: &dashboardURL, + }, table, "DashboardURL: grafana.example.com"}, + {"dashboardURLEmpty", v1beta1.ServiceInstanceStatus{}, table, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var stringBuilder strings.Builder + tt.table = NewDetailsTable(&stringBuilder) + appendInstanceDashboardURL(tt.status, tt.table) + tt.table.Render() + actualString := strings.Trim(stringBuilder.String(), " \n") + + if actualString != tt.expectedString { + t.Fatalf("%v failed; expected %v; got %v", tt.name, tt.expectedString, actualString) + } + }) + } +}