Skip to content

Commit

Permalink
feat: remove path existence check on Container.AbsolutePath
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjarosch committed Feb 25, 2024
1 parent 927977c commit 0749ffc
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 36 deletions.
7 changes: 2 additions & 5 deletions data/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ func (container *Container) HasPath(path Path) bool {
// This function satisfies the [skipper.AbsolutePathMaker] interface.
// The second parameter is usually required to determine to which Class the path is relative to.
// In this case, that context is not needed as there is only the one container context.
// In case the path is empty or it is not valid within the given context, an error is returned.
// The function does not check whether the path is valid within the container.
// This is to allow setting new paths, which do not yet exist.
func (container *Container) AbsolutePath(path Path, _ Path) (Path, error) {
if path == nil || len(path) == 0 {
return nil, ErrEmptyPath
Expand All @@ -224,9 +225,5 @@ func (container *Container) AbsolutePath(path Path, _ Path) (Path, error) {
path = path.Prepend(container.rootKey)
}

if !container.HasPath(path) {
return nil, fmt.Errorf("%w: path does not exist: %s", ErrCannotResolveAbsolutePath, path)
}

return path, nil
}
6 changes: 0 additions & 6 deletions data/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,6 @@ func TestContainerAbsolutePath(t *testing.T) {
expected: NewPath("test.foo.bar.baz"),
err: nil,
},
{
name: "invalid relative path",
input: NewPath("some.path.which.does.not.exist"),
expected: nil,
err: ErrCannotResolveAbsolutePath,
},
{
name: "path is container name",
input: NewPath(containerName),
Expand Down
18 changes: 0 additions & 18 deletions inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/stretchr/testify/assert"

"github.com/lukasjarosch/skipper"
. "github.com/lukasjarosch/skipper"
"github.com/lukasjarosch/skipper/data"
)
Expand Down Expand Up @@ -46,16 +45,6 @@ func TestInventoryGet(t *testing.T) {

// Test: get existing path without scope prefix and without default scope
val, err = inv.Get("pizza.description")
assert.NoError(t, err)
assert.NotNil(t, val.Raw)

// Test: get existing path without scope prefix and with default scope
err = inv.SetDefaultScope(DataScope)
assert.NoError(t, err)
val, err = inv.Get("pizza.description")
assert.NoError(t, err)
assert.NotNil(t, val.Raw)
}

func TestInventorySetDefaultScope(t *testing.T) {
inv, _ := NewInventory()
Expand Down Expand Up @@ -125,13 +114,6 @@ func TestInventoryAbsolutePath(t *testing.T) {
expected: nil,
err: ErrPathNotFound,
},
{
name: "path is not valid within the given context",
path: data.NewPath("unknown"),
context: data.NewPath("data.person.gender"),
expected: nil,
err: data.ErrCannotResolveAbsolutePath,
},
{
name: "context is only scope name",
path: data.NewPath("name"),
Expand Down
7 changes: 0 additions & 7 deletions registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,6 @@ func TestRegistryAbsolutePath(t *testing.T) {
expected: data.NewPath("person.name"),
err: nil,
},
{
name: "path does not exist in context class",
path: data.NewPath("does.not.exist"),
context: data.NewPath("person.contact.email"),
expected: nil,
err: data.ErrCannotResolveAbsolutePath,
},
{
name: "context path is unknown",
path: data.NewPath("name"),
Expand Down

0 comments on commit 0749ffc

Please sign in to comment.