Skip to content

Commit e8b55a8

Browse files
authored
Merge pull request #66 from philbrookes/add-pretty-json
add prettyjson output type
2 parents 4bba5e8 + 628385e commit e8b55a8

File tree

5 files changed

+242
-9
lines changed

5 files changed

+242
-9
lines changed

integration/client_get_services_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package integration
33
import (
44
"os/exec"
55
"regexp"
6+
"strings"
67
"testing"
78
)
89

@@ -13,8 +14,8 @@ func TestGetServices(t *testing.T) {
1314
regexes := []*regexp.Regexp{
1415
regexp.MustCompile("\"uid\".*?,"),
1516
regexp.MustCompile("\"resourceVersion\".*?,"),
16-
regexp.MustCompile("\"creationTimestamp\".*?,"),
17-
regexp.MustCompile("\"removedFromBrokerCatalog\".*?}"),
17+
regexp.MustCompile("\"creationTimestamp\": \".*?\""),
18+
regexp.MustCompile("\"removedFromBrokerCatalog\": (true|false)"),
1819
}
1920

2021
tests := []struct {
@@ -44,12 +45,12 @@ func TestGetServices(t *testing.T) {
4445
expected := LoadSnapshot(t, getServicesTestPath+test.fixture)
4546

4647
if test.name == "json output" {
47-
actual = CleanStringByRegex(actual, regexes)
48-
expected = CleanStringByRegex(expected, regexes)
48+
actual = strings.TrimSpace(CleanStringByRegex(actual, regexes))
49+
expected = strings.TrimSpace(CleanStringByRegex(expected, regexes))
4950
}
5051

5152
if actual != expected {
52-
t.Fatalf("actual = \n%s, expected = \n%s", actual, expected)
53+
t.Fatalf("actual = \n'%s', expected = \n'%s'", actual, expected)
5354
}
5455
})
5556
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
{"version":"1","client_id":"myapp-cordova","services":[]}
1+
{
2+
"version": "1",
3+
4+
5+
"client_id": "myapp-cordova",
6+
"services": []
7+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,199 @@
1-
{"metadata":{},"items":[{"metadata":{"name":"1522a4d0e2fbf86a26cbe096eb1b6b2d","selfLink":"/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/1522a4d0e2fbf86a26cbe096eb1b6b2d","uid":"4ac8191c-0740-11e8-98ce-0242ac110004","resourceVersion":"39","creationTimestamp":"2018-02-01T11:08:54Z"},"spec":{"clusterServiceBrokerName":"ansible-service-broker","externalName":"dh-unifiedpush-apb","externalID":"1522a4d0e2fbf86a26cbe096eb1b6b2d","description":"AeroGear UnifiedPush Server","bindable":true,"binding_retrievable":false,"planUpdatable":false,"externalMetadata":{"dependencies":["MySQL:55"],"displayName":"AeroGear UPS","documentationUrl":"https://aerogear.org/push","imageUrl":"https://pbs.twimg.com/profile_images/1794440005/aerogear_icon-1_400x400.png","providerDisplayName":"Red Hat, Inc.","serviceName":"ups"},"tags":["mobile-service"]},"status":{"removedFromBrokerCatalog":false}},{"metadata":{"name":"2b825339e8d685a78476621a252beea8","selfLink":"/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/2b825339e8d685a78476621a252beea8","uid":"4aac5f37-0740-11e8-98ce-0242ac110004","resourceVersion":"32","creationTimestamp":"2018-02-01T11:08:54Z"},"spec":{"clusterServiceBrokerName":"ansible-service-broker","externalName":"dh-3scale-apb","externalID":"2b825339e8d685a78476621a252beea8","description":"Unlock the power of your APIs. This will deploy Apicast to your Openshift cluster and connect it to a dedicated Redis. For this to function correctly it needs to be configured with a token and domain for the account it should pull it's configuration values from (usually in 3scale.net).\nYou can create an account with 3scale.net here: https://www.3scale.net/signup/\n","bindable":true,"binding_retrievable":false,"planUpdatable":false,"externalMetadata":{"displayName":"3Scale","documentationUrl":"https://www.3scale.net/api-management/interactive-api-documentation/","imageUrl":"https://avatars1.githubusercontent.com/u/21415?s=200\u0026v=4","providerDisplayName":"Red Hat, Inc.","serviceName":"3scale"},"tags":["mobile-service"]},"status":{"removedFromBrokerCatalog":false}},{"metadata":{"name":"9623d53183cc78619f888ea8499c678e","selfLink":"/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/9623d53183cc78619f888ea8499c678e","uid":"4aaea9cf-0740-11e8-98ce-0242ac110004","resourceVersion":"35","creationTimestamp":"2018-02-01T11:08:54Z"},"spec":{"clusterServiceBrokerName":"ansible-service-broker","externalName":"dh-metrics-apb","externalID":"9623d53183cc78619f888ea8499c678e","description":"Installs a metrics service based on Prometheus and Grafana","bindable":false,"binding_retrievable":false,"planUpdatable":false,"externalMetadata":{"displayName":"Metrics","documentationUrl":"https://prometheus.io/docs/introduction/overview/","imageUrl":"https://avatars1.githubusercontent.com/u/3380462?s=200\u0026v=4","providerDisplayName":"Red Hat, Inc.","serviceName":"metrics"},"tags":["mobile-service"]},"status":{"removedFromBrokerCatalog":false}},{"metadata":{"name":"a0c0c2478554458d5c77abc95f0473a3","selfLink":"/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/a0c0c2478554458d5c77abc95f0473a3","uid":"4aad7ed5-0740-11e8-98ce-0242ac110004","resourceVersion":"34","creationTimestamp":"2018-02-01T11:08:54Z"},"spec":{"clusterServiceBrokerName":"ansible-service-broker","externalName":"dh-aerogear-digger-apb","externalID":"a0c0c2478554458d5c77abc95f0473a3","description":"Mobile CI/CD service that integrates with Jenkins Pipelines to test and build your mobile binaries.","bindable":false,"binding_retrievable":false,"planUpdatable":false,"externalMetadata":{"displayName":"Mobile CI/CD","documentationUrl":"https://aerogear.org/digger/","imageUrl":"https://aerogear.org/img/aerogeardigger_icon_32px_cropped.png","longDescription":"To use the Mobile CI/CD service you must first agree to the Android SDK License Agreement. By checking this box you are agreeing to the Android Software Development Kit License agreement which can be read at the following URL: https://developer.android.com/studio/terms.html\n\n. If the box is not checked the installer will take no action.","providerDisplayName":"Red Hat, Inc.","serviceName":"aerogear-digger"},"tags":["mobile-service"]},"status":{"removedFromBrokerCatalog":false}},{"metadata":{"name":"b95513950bb3f132de25d58fb75f8dca","selfLink":"/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/b95513950bb3f132de25d58fb75f8dca","uid":"4aacf96d-0740-11e8-98ce-0242ac110004","resourceVersion":"33","creationTimestamp":"2018-02-01T11:08:54Z"},"spec":{"clusterServiceBrokerName":"ansible-service-broker","externalName":"dh-keycloak-apb","externalID":"b95513950bb3f132de25d58fb75f8dca","description":"Keycloak - Open Source Identity and Access Management","bindable":true,"binding_retrievable":false,"planUpdatable":false,"externalMetadata":{"dependencies":["Postgresql:9.5"],"displayName":"Keycloak","documentationUrl":"http://www.keycloak.org/documentation.html","imageUrl":"https://pbs.twimg.com/profile_images/702119821979344897/oAC05cEB_400x400.png","providerDisplayName":"Red Hat, Inc.","serviceName":"keycloak"},"tags":["mobile-service"]},"status":{"removedFromBrokerCatalog":false}},{"metadata":{"name":"c57e94c36c1e7f6bb41cf7c589d9eb08","selfLink":"/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/c57e94c36c1e7f6bb41cf7c589d9eb08","uid":"4ab033d5-0740-11e8-98ce-0242ac110004","resourceVersion":"38","creationTimestamp":"2018-02-01T11:08:54Z"},"spec":{"clusterServiceBrokerName":"ansible-service-broker","externalName":"dh-fh-sync-server-apb","externalID":"c57e94c36c1e7f6bb41cf7c589d9eb08","description":"The FeedHenry Sync Server APB","bindable":false,"binding_retrievable":false,"planUpdatable":false,"externalMetadata":{"displayName":"FeedHenry Sync Server","documentationUrl":"http://feedhenry.org/projects/#data-synchronization","imageUrl":"https://avatars3.githubusercontent.com/u/772226?s=200\u0026v=4","integrations":"keycloak,apiKeys","providerDisplayName":"Red Hat, Inc.","serviceName":"fh-sync-server"},"tags":["mobile-service"]},"status":{"removedFromBrokerCatalog":false}}]}
1+
{
2+
"metadata": {},
3+
"items": [
4+
{
5+
"metadata": {
6+
"name": "1522a4d0e2fbf86a26cbe096eb1b6b2d",
7+
"selfLink": "/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/1522a4d0e2fbf86a26cbe096eb1b6b2d",
8+
"uid": "12368a77-0c06-11e8-896a-0242ac110004",
9+
"resourceVersion": "38",
10+
"creationTimestamp": "2018-02-07T12:54:44Z"
11+
},
12+
"spec": {
13+
"clusterServiceBrokerName": "ansible-service-broker",
14+
"externalName": "dh-unifiedpush-apb",
15+
"externalID": "1522a4d0e2fbf86a26cbe096eb1b6b2d",
16+
"description": "AeroGear UnifiedPush Server",
17+
"bindable": true,
18+
"binding_retrievable": false,
19+
"planUpdatable": false,
20+
"externalMetadata": {
21+
"dependencies": [
22+
"MySQL:55"
23+
],
24+
"displayName": "AeroGear UPS",
25+
"documentationUrl": "https://aerogear.org/push",
26+
"imageUrl": "https://pbs.twimg.com/profile_images/1794440005/aerogear_icon-1_400x400.png",
27+
"providerDisplayName": "Red Hat, Inc.",
28+
"serviceName": "ups"
29+
},
30+
"tags": [
31+
"mobile-service"
32+
]
33+
},
34+
"status": {
35+
"removedFromBrokerCatalog": false
36+
}
37+
},
38+
{
39+
"metadata": {
40+
"name": "2b825339e8d685a78476621a252beea8",
41+
"selfLink": "/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/2b825339e8d685a78476621a252beea8",
42+
"uid": "1255238e-0c06-11e8-896a-0242ac110004",
43+
"resourceVersion": "39",
44+
"creationTimestamp": "2018-02-07T12:54:45Z"
45+
},
46+
"spec": {
47+
"clusterServiceBrokerName": "ansible-service-broker",
48+
"externalName": "dh-3scale-apb",
49+
"externalID": "2b825339e8d685a78476621a252beea8",
50+
"description": "Unlock the power of your APIs. This will deploy Apicast to your Openshift cluster and connect it to a dedicated Redis. For this to function correctly it needs to be configured with a token and domain for the account it should pull it's configuration values from (usually in 3scale.net).\nYou can create an account with 3scale.net here: https://www.3scale.net/signup/\n",
51+
"bindable": true,
52+
"binding_retrievable": false,
53+
"planUpdatable": false,
54+
"externalMetadata": {
55+
"displayName": "3Scale",
56+
"documentationUrl": "https://www.3scale.net/api-management/interactive-api-documentation/",
57+
"imageUrl": "https://avatars1.githubusercontent.com/u/21415?s=200\u0026v=4",
58+
"providerDisplayName": "Red Hat, Inc.",
59+
"serviceName": "3scale"
60+
},
61+
"tags": [
62+
"mobile-service"
63+
]
64+
},
65+
"status": {
66+
"removedFromBrokerCatalog": false
67+
}
68+
},
69+
{
70+
"metadata": {
71+
"name": "9623d53183cc78619f888ea8499c678e",
72+
"selfLink": "/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/9623d53183cc78619f888ea8499c678e",
73+
"uid": "12180ceb-0c06-11e8-896a-0242ac110004",
74+
"resourceVersion": "37",
75+
"creationTimestamp": "2018-02-07T12:54:44Z"
76+
},
77+
"spec": {
78+
"clusterServiceBrokerName": "ansible-service-broker",
79+
"externalName": "dh-metrics-apb",
80+
"externalID": "9623d53183cc78619f888ea8499c678e",
81+
"description": "Installs a metrics service based on Prometheus and Grafana",
82+
"bindable": false,
83+
"binding_retrievable": false,
84+
"planUpdatable": false,
85+
"externalMetadata": {
86+
"displayName": "Metrics",
87+
"documentationUrl": "https://prometheus.io/docs/introduction/overview/",
88+
"imageUrl": "https://avatars1.githubusercontent.com/u/3380462?s=200\u0026v=4",
89+
"providerDisplayName": "Red Hat, Inc.",
90+
"serviceName": "metrics"
91+
},
92+
"tags": [
93+
"mobile-service"
94+
]
95+
},
96+
"status": {
97+
"removedFromBrokerCatalog": false
98+
}
99+
},
100+
{
101+
"metadata": {
102+
"name": "a0c0c2478554458d5c77abc95f0473a3",
103+
"selfLink": "/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/a0c0c2478554458d5c77abc95f0473a3",
104+
"uid": "1209b137-0c06-11e8-896a-0242ac110004",
105+
"resourceVersion": "33",
106+
"creationTimestamp": "2018-02-07T12:54:44Z"
107+
},
108+
"spec": {
109+
"clusterServiceBrokerName": "ansible-service-broker",
110+
"externalName": "dh-aerogear-digger-apb",
111+
"externalID": "a0c0c2478554458d5c77abc95f0473a3",
112+
"description": "Mobile CI/CD service that integrates with Jenkins Pipelines to test and build your mobile binaries.",
113+
"bindable": false,
114+
"binding_retrievable": false,
115+
"planUpdatable": false,
116+
"externalMetadata": {
117+
"displayName": "Mobile CI/CD",
118+
"documentationUrl": "https://aerogear.org/digger/",
119+
"imageUrl": "https://aerogear.org/img/aerogeardigger_icon_32px_cropped.png",
120+
"longDescription": "To use the Mobile CI/CD service you must first agree to the Android SDK License Agreement. By checking this box you are agreeing to the Android Software Development Kit License agreement which can be read at the following URL: https://developer.android.com/studio/terms.html\n\n. If the box is not checked the installer will take no action.",
121+
"providerDisplayName": "Red Hat, Inc.",
122+
"serviceName": "aerogear-digger"
123+
},
124+
"tags": [
125+
"mobile-service"
126+
]
127+
},
128+
"status": {
129+
"removedFromBrokerCatalog": false
130+
}
131+
},
132+
{
133+
"metadata": {
134+
"name": "b95513950bb3f132de25d58fb75f8dca",
135+
"selfLink": "/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/b95513950bb3f132de25d58fb75f8dca",
136+
"uid": "120a3d53-0c06-11e8-896a-0242ac110004",
137+
"resourceVersion": "34",
138+
"creationTimestamp": "2018-02-07T12:54:44Z"
139+
},
140+
"spec": {
141+
"clusterServiceBrokerName": "ansible-service-broker",
142+
"externalName": "dh-keycloak-apb",
143+
"externalID": "b95513950bb3f132de25d58fb75f8dca",
144+
"description": "Keycloak - Open Source Identity and Access Management",
145+
"bindable": true,
146+
"binding_retrievable": false,
147+
"planUpdatable": false,
148+
"externalMetadata": {
149+
"dependencies": [
150+
"Postgresql:9.5"
151+
],
152+
"displayName": "Keycloak",
153+
"documentationUrl": "http://www.keycloak.org/documentation.html",
154+
"imageUrl": "https://pbs.twimg.com/profile_images/702119821979344897/oAC05cEB_400x400.png",
155+
"providerDisplayName": "Red Hat, Inc.",
156+
"serviceName": "keycloak"
157+
},
158+
"tags": [
159+
"mobile-service"
160+
]
161+
},
162+
"status": {
163+
"removedFromBrokerCatalog": false
164+
}
165+
},
166+
{
167+
"metadata": {
168+
"name": "c57e94c36c1e7f6bb41cf7c589d9eb08",
169+
"selfLink": "/apis/servicecatalog.k8s.io/v1beta1/clusterserviceclasses/c57e94c36c1e7f6bb41cf7c589d9eb08",
170+
"uid": "12092f0e-0c06-11e8-896a-0242ac110004",
171+
"resourceVersion": "32",
172+
"creationTimestamp": "2018-02-07T12:54:44Z"
173+
},
174+
"spec": {
175+
"clusterServiceBrokerName": "ansible-service-broker",
176+
"externalName": "dh-fh-sync-server-apb",
177+
"externalID": "c57e94c36c1e7f6bb41cf7c589d9eb08",
178+
"description": "The FeedHenry Sync Server APB",
179+
"bindable": false,
180+
"binding_retrievable": false,
181+
"planUpdatable": false,
182+
"externalMetadata": {
183+
"displayName": "FeedHenry Sync Server",
184+
"documentationUrl": "http://feedhenry.org/projects/#data-synchronization",
185+
"imageUrl": "https://avatars3.githubusercontent.com/u/772226?s=200\u0026v=4",
186+
"integrations": "keycloak,apiKeys",
187+
"providerDisplayName": "Red Hat, Inc.",
188+
"serviceName": "fh-sync-server"
189+
},
190+
"tags": [
191+
"mobile-service"
192+
]
193+
},
194+
"status": {
195+
"removedFromBrokerCatalog": false
196+
}
197+
}
198+
]
199+
}

pkg/cmd/clientConfig_test.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ func TestClientConfigCmd_GetClientConfigCmd(t *testing.T) {
8787
cobraCmd: getFakeCbrCmd(),
8888
ExpectError: false,
8989
ValidateOut: func(out bytes.Buffer) error {
90-
expected := `{"version":"1","cluster_name":"test","namespace":"testing-ns","client_id":"client-id","services":[]}`
90+
expected := `{
91+
"version": "1",
92+
"cluster_name": "test",
93+
"namespace": "testing-ns",
94+
"client_id": "client-id",
95+
"services": []
96+
}`
9197
if strings.TrimSpace(out.String()) != expected {
9298
return errors.New(fmt.Sprintf("expected: '%v', got: '%v'", expected, strings.TrimSpace(out.String())))
9399
}
@@ -156,7 +162,28 @@ func TestClientConfigCmd_GetClientConfigCmd(t *testing.T) {
156162
cobraCmd: getFakeCbrCmd(),
157163
ExpectError: false,
158164
ValidateOut: func(out bytes.Buffer) error {
159-
expected := `{"version":"1","cluster_name":"test","namespace":"testing-ns","client_id":"client-id","services":[{"id":"test-service","name":"test-service","type":"","url":"","config":{}},{"id":"keycloak","name":"keycloak","type":"","url":"","config":{}}]}`
165+
expected := `{
166+
"version": "1",
167+
"cluster_name": "test",
168+
"namespace": "testing-ns",
169+
"client_id": "client-id",
170+
"services": [
171+
{
172+
"id": "test-service",
173+
"name": "test-service",
174+
"type": "",
175+
"url": "",
176+
"config": {}
177+
},
178+
{
179+
"id": "keycloak",
180+
"name": "keycloak",
181+
"type": "",
182+
"url": "",
183+
"config": {}
184+
}
185+
]
186+
}`
160187
if strings.TrimSpace(out.String()) != expected {
161188
return errors.New(fmt.Sprintf("expected: '%v', got: '%v'", expected, strings.TrimSpace(out.String())))
162189
}

pkg/cmd/output/renderer.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Renderer struct {
2929
func (r *Renderer) Render(cmd, outputType string, data interface{}) error {
3030
if strings.ToLower(outputType) == "json" {
3131
encoder := json.NewEncoder(r.out)
32+
encoder.SetIndent("", " ")
3233
return encoder.Encode(data)
3334
}
3435

0 commit comments

Comments
 (0)