Skip to content

Commit

Permalink
feat: remove default scope on inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjarosch committed Feb 25, 2024
1 parent 0749ffc commit 2d05e48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
24 changes: 2 additions & 22 deletions inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ var (
)

type Inventory struct {
scopes map[Scope]*Registry
defaultScope Scope
scopes map[Scope]*Registry
}

func NewInventory() (*Inventory, error) {
return &Inventory{
scopes: make(map[Scope]*Registry),
defaultScope: "",
scopes: make(map[Scope]*Registry),
}, nil
}

Expand Down Expand Up @@ -120,24 +118,6 @@ func (inv *Inventory) SetPath(path data.Path, value interface{}) error {
return inv.Set(path.String(), value)
}

func (inv *Inventory) SetDefaultScope(scope Scope) error {
if scope == "" {
return ErrEmptyScope
}

if _, exists := inv.scopes[scope]; !exists {
return fmt.Errorf("%s: %w", scope, ErrScopeDoesNotExist)
}

inv.defaultScope = scope

return nil
}

func (inv *Inventory) HasDefaultScope() bool {
return inv.defaultScope != ""
}

func (inv *Inventory) Scopes() []Scope {
var scopes []Scope
for scope := range inv.scopes {
Expand Down
20 changes: 2 additions & 18 deletions inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,8 @@ func TestInventoryGet(t *testing.T) {

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

func TestInventorySetDefaultScope(t *testing.T) {
inv, _ := NewInventory()

err := inv.RegisterScope(DataScope, skipper.NewRegistry())
assert.NoError(t, err)

// Test: empty scope
err = inv.SetDefaultScope("")
assert.ErrorIs(t, err, ErrEmptyScope)

// Test: not existing scope
err = inv.SetDefaultScope("something")
assert.ErrorIs(t, err, ErrScopeDoesNotExist)

// Test: valid, existing scope
err = inv.SetDefaultScope(DataScope)
assert.NoError(t, err)
assert.ErrorIs(t, err, ErrPathNotFound)
assert.Nil(t, val.Raw)
}

func TestInventoryAbsolutePath(t *testing.T) {
Expand Down

0 comments on commit 2d05e48

Please sign in to comment.