Skip to content

Commit

Permalink
Clean-up imports and formatting
Browse files Browse the repository at this point in the history
Run clean-up to re-organise imports consistenly.

Simplify code where possible.

Fix TYPOs.
  • Loading branch information
HeavyWombat committed Mar 19, 2021
1 parent 1fef434 commit 6029534
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func deletePath(node *yamlv3.Node, path Path) (*yamlv3.Node, error) {
}

var (
lastPathElement PathElement = path.PathElements[len(path.PathElements)-1]
lastPathElement = path.PathElements[len(path.PathElements)-1]
deletedNode *yamlv3.Node = nil
)

Expand Down
3 changes: 2 additions & 1 deletion delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/gonvenience/ytbx"
"gopkg.in/yaml.v3"

"github.com/gonvenience/ytbx"
)

var _ = Describe("Delete from YAML", func() {
Expand Down
2 changes: 1 addition & 1 deletion getting.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func grabByPath(node *yamlv3.Node, path Path) (*yamlv3.Node, error) {
pointer = entry

// Complex List, where each list entry is a Key/Value map and the entry is
// identified by name using an indentifier (e.g. name, key, or id)
// identified by name using an identifier (e.g. name, key, or id)
case element.isComplexListElement():
if pointer.Kind != yamlv3.SequenceNode {
return nil,
Expand Down
7 changes: 5 additions & 2 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func (d *DecoderProxy) Decode(v interface{}) error {
return d.standard.Decode(v)
}

// HumanReadableLocationInformation create a nicely decorated information about the provided input location. It will output the absolut path of the file (rather than the possibly relative location), or it will show the URL in the usual look-and-feel of URIs.
// HumanReadableLocationInformation create a nicely decorated information about
// the provided input location. It will output the absolute path of the file
// rather than the possibly relative location, or it will show the URL in the
// usual look-and-feel of URIs.
func HumanReadableLocationInformation(inputFile InputFile) string {
var buf bytes.Buffer

Expand Down Expand Up @@ -283,7 +286,7 @@ func LoadTOMLDocuments(input []byte) ([]*yamlv3.Node, error) {
}

func getBytesFromLocation(location string) ([]byte, error) {
// Handle special location "-" which referes to STDIN stream
// Handle special location "-" which refers to STDIN stream
if IsStdin(location) {
return ioutil.ReadAll(os.Stdin)
}
Expand Down
4 changes: 3 additions & 1 deletion input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/gonvenience/ytbx"
. "github.com/gorilla/mux"

. "github.com/gonvenience/ytbx"
)

var _ = Describe("Input test cases", func() {
Expand Down Expand Up @@ -91,6 +92,7 @@ var _ = Describe("Input test cases", func() {
It("should fail if the HTTP request fails", func() {
fullUrl := server.URL + "/v1/assets/examples/does-not-exist.yml"
_, err := LoadFile(fullUrl)
Expect(err).ToNot(BeNil())
Expect(err.Error()).To(BeEquivalentTo("unable to load data from " + fullUrl + ": failed to retrieve data from location " + fullUrl + ": File not found: examples/does-not-exist.yml"))
})
})
Expand Down
4 changes: 2 additions & 2 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
GoPatchStyle
)

// Path points to a section in a data struture by using names to identify the
// Path points to a section in a data structure by using names to identify the
// location.
// Example:
// ---
Expand Down Expand Up @@ -318,7 +318,7 @@ func ParseGoPatchStylePathString(path string) (Path, error) {
return Path{DocumentIdx: 0, PathElements: nil}, nil
}

// Poor mans solution to deal with escaped slashes, replace them with a "safe"
// Hacky solution to deal with escaped slashes, replace them with a "safe"
// replacement string that is later resolved into a simple slash
path = strings.Replace(path, `\/`, `%2F`, -1)

Expand Down
41 changes: 21 additions & 20 deletions path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
. "github.com/onsi/gomega"

. "github.com/gonvenience/ytbx"

yamlv3 "gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -156,24 +157,24 @@ var _ = Describe("path tests", func() {
listOfPaths := []Path{
{
DocumentIdx: 0, PathElements: []PathElement{
{Idx: -1, Key: "", Name: "yaml"},
{Idx: -1, Key: "", Name: "structure"},
{Idx: -1, Key: "", Name: "somekey"},
},
{Idx: -1, Key: "", Name: "yaml"},
{Idx: -1, Key: "", Name: "structure"},
{Idx: -1, Key: "", Name: "somekey"},
},
},
{
DocumentIdx: 0, PathElements: []PathElement{
{Idx: -1, Key: "", Name: "yaml"},
{Idx: -1, Key: "", Name: "structure"},
{Idx: -1, Key: "", Name: "dot"},
},
{Idx: -1, Key: "", Name: "yaml"},
{Idx: -1, Key: "", Name: "structure"},
{Idx: -1, Key: "", Name: "dot"},
},
},
{
DocumentIdx: 0, PathElements: []PathElement{
{Idx: -1, Key: "", Name: "list"},
{Idx: -1, Key: "name", Name: "sametwo"},
{Idx: -1, Key: "", Name: "somekey"},
},
{Idx: -1, Key: "", Name: "list"},
{Idx: -1, Key: "name", Name: "sametwo"},
{Idx: -1, Key: "", Name: "somekey"},
},
},
}

Expand All @@ -187,17 +188,17 @@ var _ = Describe("path tests", func() {
listOfPathsWithSameValue := []Path{
{
DocumentIdx: 0, PathElements: []PathElement{
{Idx: -1, Key: "", Name: "yaml"},
{Idx: -1, Key: "", Name: "structure"},
{Idx: -1, Key: "", Name: "dot"},
},
{Idx: -1, Key: "", Name: "yaml"},
{Idx: -1, Key: "", Name: "structure"},
{Idx: -1, Key: "", Name: "dot"},
},
},
{
DocumentIdx: 0, PathElements: []PathElement{
{Idx: -1, Key: "", Name: "list"},
{Idx: -1, Key: "name", Name: "sametwo"},
{Idx: -1, Key: "", Name: "somekey"},
},
{Idx: -1, Key: "", Name: "list"},
{Idx: -1, Key: "name", Name: "sametwo"},
{Idx: -1, Key: "", Name: "somekey"},
},
},
}

Expand Down
4 changes: 2 additions & 2 deletions restructure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

var _ = Describe("Restructure order of map keys", func() {
Context("YAML MapSlice key reorderings of the MapSlice itself", func() {
Context("YAML MapSlice key reordering of the MapSlice itself", func() {
It("should restructure Concourse root level keys", func() {
example := yml("{ groups: [], jobs: [], resources: [], resource_types: [] }")
RestructureObject(example)
Expand All @@ -48,7 +48,7 @@ var _ = Describe("Restructure order of map keys", func() {
})
})

Context("YAML MapSlice key reorderings of the MapSlice values", func() {
Context("YAML MapSlice key reordering of the MapSlice values", func() {
It("should restructure Concourse resource keys as part as part of a MapSlice value", func() {
example := yml("{ resources: [ { privileged: false, source: { branch: foo, paths: [] }, name: myname, type: mytype } ] }")
RestructureObject(example)
Expand Down
6 changes: 4 additions & 2 deletions ytbx_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import (
"strconv"
"testing"

. "github.com/gonvenience/bunt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/types"

"github.com/gonvenience/bunt"
"github.com/gonvenience/neat"
"github.com/gonvenience/ytbx"
yamlv3 "gopkg.in/yaml.v3"

"github.com/gonvenience/ytbx"
)

var exampleTOML = `
Expand Down Expand Up @@ -159,6 +160,7 @@ func grab(node *yamlv3.Node, path string) interface{} {
func grabError(node *yamlv3.Node, path string) string {
value, err := ytbx.Grab(node, path)
Expect(value).To(BeNil())
Expect(err).ToNot(BeNil())
return err.Error()
}

Expand Down

0 comments on commit 6029534

Please sign in to comment.