|
| 1 | +package test_test |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/onsi/ginkgo" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + |
| 7 | + "github.com/cppforlife/go-cli-ui/ui" |
| 8 | + . "github.com/cppforlife/go-cli-ui/ui/test" |
| 9 | +) |
| 10 | + |
| 11 | +var _ = Describe("JSONUIFromBytes", func() { |
| 12 | + const ( |
| 13 | + example = ` |
| 14 | +{ |
| 15 | + "Tables": [ |
| 16 | + { |
| 17 | + "Content": "services", |
| 18 | + "Header": { |
| 19 | + "created_at": "Created At", |
| 20 | + "domain": "Domain", |
| 21 | + "internal_domain": "Internal Domain", |
| 22 | + "name": "Name" |
| 23 | + }, |
| 24 | + "Rows": [ |
| 25 | + { |
| 26 | + "created_at": "2018-07-31T12:27:45-07:00", |
| 27 | + "domain": "foo3.default.example.com", |
| 28 | + "internal_domain": "foo3.default.svc.cluster.local", |
| 29 | + "name": "foo3" |
| 30 | + }, |
| 31 | + { |
| 32 | + "created_at": "2018-07-26T16:47:39-07:00", |
| 33 | + "domain": "helloworld-go.default.example.com", |
| 34 | + "internal_domain": "helloworld-go.default.svc.cluster.local", |
| 35 | + "name": "helloworld-go" |
| 36 | + } |
| 37 | + ], |
| 38 | + "Notes": null |
| 39 | + } |
| 40 | + ], |
| 41 | + "Blocks": null, |
| 42 | + "Lines": null |
| 43 | +} |
| 44 | +` |
| 45 | + ) |
| 46 | + |
| 47 | + It("properly parses JSON UI output", func() { |
| 48 | + resp := JSONUIFromBytes(nil, []byte(example)) |
| 49 | + Expect(resp).To(Equal(ui.JSONUIResp{ |
| 50 | + Tables: []ui.JSONUITableResp{ |
| 51 | + { |
| 52 | + Content: "services", |
| 53 | + Header: map[string]string{ |
| 54 | + "domain": "Domain", |
| 55 | + "internal_domain": "Internal Domain", |
| 56 | + "name": "Name", |
| 57 | + "created_at": "Created At", |
| 58 | + }, |
| 59 | + Rows: []map[string]string{ |
| 60 | + { |
| 61 | + "internal_domain": "foo3.default.svc.cluster.local", |
| 62 | + "name": "foo3", |
| 63 | + "created_at": "2018-07-31T12:27:45-07:00", |
| 64 | + "domain": "foo3.default.example.com", |
| 65 | + }, |
| 66 | + { |
| 67 | + "name": "helloworld-go", |
| 68 | + "created_at": "2018-07-26T16:47:39-07:00", |
| 69 | + "domain": "helloworld-go.default.example.com", |
| 70 | + "internal_domain": "helloworld-go.default.svc.cluster.local", |
| 71 | + }, |
| 72 | + }, |
| 73 | + Notes: nil, |
| 74 | + }, |
| 75 | + }, |
| 76 | + Blocks: nil, |
| 77 | + Lines: nil, |
| 78 | + })) |
| 79 | + }) |
| 80 | +}) |
0 commit comments