From 0749ffcfa6d8979f72776d956a1985c1b20d869e Mon Sep 17 00:00:00 2001 From: Lukas Jarosch Date: Mon, 26 Feb 2024 00:41:19 +0100 Subject: [PATCH] feat: remove path existence check on `Container.AbsolutePath` --- data/container.go | 7 ++----- data/container_test.go | 6 ------ inventory_test.go | 18 ------------------ registry_test.go | 7 ------- 4 files changed, 2 insertions(+), 36 deletions(-) diff --git a/data/container.go b/data/container.go index 44f4786..9bfc711 100644 --- a/data/container.go +++ b/data/container.go @@ -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 @@ -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 } diff --git a/data/container_test.go b/data/container_test.go index d85d4f1..c3e6886 100644 --- a/data/container_test.go +++ b/data/container_test.go @@ -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), diff --git a/inventory_test.go b/inventory_test.go index 8024a54..c922bb2 100644 --- a/inventory_test.go +++ b/inventory_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/assert" - "github.com/lukasjarosch/skipper" . "github.com/lukasjarosch/skipper" "github.com/lukasjarosch/skipper/data" ) @@ -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() @@ -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"), diff --git a/registry_test.go b/registry_test.go index 7dc719b..5e60c9e 100644 --- a/registry_test.go +++ b/registry_test.go @@ -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"),