Skip to content

Commit

Permalink
added asciinema video, cleanup test
Browse files Browse the repository at this point in the history
  • Loading branch information
damianoneill committed Nov 18, 2019
1 parent 2f56284 commit d7e7b25
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 28 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ A command line tool for interacting with [Juniper Healthbot](https://www.juniper

> Note Device Group functionality is limited currently, this will be updated after Healthbot 2.1 is released.
[![asciicast](https://asciinema.org/a/FsdPZpORfIuciQ70rTgGvtf4M.svg)](https://asciinema.org/a/FsdPZpORfIuciQ70rTgGvtf4M)

## Synopsis

A tool for interacting with Healthbot over the REST API.
Expand Down
16 changes: 10 additions & 6 deletions cmd/extract_installation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ import (
"gopkg.in/resty.v1"
)

func appendResourceBody(backup *[]byte, responseBody []byte) (err error) {
func removeBracketsFromJSONObject(src []byte) (bare []byte, err error) {
// remove all whitespace / carriage returns, etc.
buffer := new(bytes.Buffer)
err = json.Compact(buffer, responseBody)
err = json.Compact(buffer, src)
if err != nil {
return
}
// remove outer brackets
by := bytes.TrimPrefix(buffer.Bytes(), []byte("{"))
by = bytes.TrimSuffix(by, []byte("}"))
bare = bytes.TrimPrefix(buffer.Bytes(), []byte("{"))
bare = bytes.TrimSuffix(bare, []byte("}"))
return
}

func appendResourceBody(backup *[]byte, responseBody []byte) (err error) {
b, err := removeBracketsFromJSONObject(responseBody)
// append to main json object and add comma in advance of next object being added
*backup = append(*backup, by...)
*backup = append(*backup, b...)
*backup = append(*backup, ',')
return
}
Expand Down
18 changes: 16 additions & 2 deletions cmd/extract_installation_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cmd

import "testing"
import (
"strings"
"testing"

import "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)

func Test_appendResourceBody(t *testing.T) {
// fugly test
Expand All @@ -14,3 +17,14 @@ func Test_appendResourceBody(t *testing.T) {
assert.Nil(t, err, "Should not return an error %v", err)
assert.Equal(t, expected, backup, "should start with { and end with , and separate objects with a comma")
}

func Test_removeBracketsFromJSONObject(t *testing.T) {
b, err := removeBracketsFromJSONObject(HelperLoadBytes(t, "devices.json"))
if err != nil {
t.Errorf("removeBracketsFromJSONObject() error = %v", err)
return
}
got := string(b)
assert.True(t, strings.HasPrefix(got, "\"device\":"), "Should start with device colon")
assert.True(t, strings.HasSuffix(got, "]"), "Should end with square bracket")
}
24 changes: 24 additions & 0 deletions cmd/testdata/devices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"device": [
{
"authentication": {
"password": {
"password": "$9$rgFlWXJZjq.5YgoGjif51RESKMX7-",
"username": "doneill"
}
},
"device-id": "mmx960-1",
"host": "172.30.177.102"
},
{
"authentication": {
"password": {
"password": "$9$TQ6CrlMXxdRhSeMW-dHq.fFnCtu",
"username": "doneill"
}
},
"device-id": "mmx960-3",
"host": "172.30.177.113"
}
]
}
2 changes: 1 addition & 1 deletion docs/h7t.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ The intent with this tool is to provide bulk or aggregate functions, that simpli
* [h7t transform](h7t_transform.md) - Transform things from proprietary formats into Healthbot dsl format
* [h7t version](h7t_version.md) - Output the current build information

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ h7t completion [flags]

* [h7t](h7t.md) - Healthbot Command Line Interface

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ h7t configure [flags]
* [h7t](h7t.md) - Healthbot Command Line Interface
* [h7t configure devices](h7t_configure_devices.md) - Load Devices with configuration

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_configure_devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ h7t configure devices [flags]

* [h7t configure](h7t_configure.md) - Configure information relating to a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ h7t docs [flags]

* [h7t](h7t.md) - Healthbot Command Line Interface

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_extract.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ h7t extract [flags]
* [h7t extract devices](h7t_extract_devices.md) - Extract Device configuration
* [h7t extract installation](h7t_extract_installation.md) - Extract installation configuration

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_extract_device-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ h7t extract device-groups [flags]

* [h7t extract](h7t_extract.md) - Extract information from a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_extract_devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ h7t extract devices [flags]

* [h7t extract](h7t_extract.md) - Extract information from a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_extract_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ h7t extract installation [flags]

* [h7t extract](h7t_extract.md) - Extract information from a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_load.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ h7t load [flags]
* [h7t load devices](h7t_load_devices.md) - Load Device configuration
* [h7t load helper-files](h7t_load_helper-files.md) - Load Helper Files

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_load_device-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ h7t load device-groups [flags]

* [h7t load](h7t_load.md) - Load information into a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_load_devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ h7t load devices [flags]

* [h7t load](h7t_load.md) - Load information into a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_load_helper-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ h7t load helper-files [flags]

* [h7t load](h7t_load.md) - Load information into a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_summarise.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ h7t summarise [flags]
* [h7t](h7t.md) - Healthbot Command Line Interface
* [h7t summarise installation](h7t_summarise_installation.md) - Summarise information collected from a Healthbot installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_summarise_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ h7t summarise installation [flags]

* [h7t summarise](h7t_summarise.md) - Summarise information from a Healthbot Installation

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ h7t transform [flags]
* [h7t](h7t.md) - Healthbot Command Line Interface
* [h7t transform devices](h7t_transform_devices.md) - Transform Devices configuration

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_transform_devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ h7t transform devices [flags]

* [h7t transform](h7t_transform.md) - Transform things from proprietary formats into Healthbot dsl format

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 1 addition & 1 deletion docs/h7t_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ h7t version [flags]

* [h7t](h7t.md) - Healthbot Command Line Interface

###### Auto generated by spf13/cobra on 15-Nov-2019
###### Auto generated by spf13/cobra on 18-Nov-2019
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ github.com/googleapis/gax-go v2.0.2+incompatible h1:silFMLAnr330+NRuag/VjIGF7TLp
github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
github.com/googleapis/gax-go/v2 v2.0.4 h1:hU4mGcQI4DaAYW+IbTun+2qEZVFxK0ySjQLTbS0VQKc=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/goreleaser/goreleaser v0.121.0 h1:CeOa4lqMI1TlPXral4PeMxWoRQv+fq0JTPUUVsl+P4Y=
github.com/goreleaser/goreleaser v0.121.0/go.mod h1:Acn33/psgsNrPClBfaYjaqmtfK4ilOIWQWYEls6nOPs=
github.com/goreleaser/goreleaser v0.122.0 h1:83xV9cUrXErdvIVnIAXYZkmZFdY139RvihqxrwswxrY=
github.com/goreleaser/goreleaser v0.122.0/go.mod h1:Acn33/psgsNrPClBfaYjaqmtfK4ilOIWQWYEls6nOPs=
github.com/goreleaser/nfpm v1.1.5 h1:bjVIflQl0b3lNQvO/b++cKMKXW+INL70AdGR+zDXWps=
Expand Down

0 comments on commit d7e7b25

Please sign in to comment.