Skip to content

Commit

Permalink
add: panics in case of empty resource name
Browse files Browse the repository at this point in the history
  • Loading branch information
ssgreg committed Sep 28, 2018
1 parent a1a7a8d commit bf0a5c3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ type builder struct {
}

func (t *builder) Shared(name string) Builder {
if name == "" {
panic("resource name could not be empty")
}

t.shs = append(t.shs, name)

return t
}

func (t *builder) Exclusive(name string) Builder {
if name == "" {
panic("resource name could not be empty")
}

t.exs = append(t.exs, name)

return t
Expand Down
8 changes: 8 additions & 0 deletions stacked_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ type stackedBuilder struct {
}

func (t *stackedBuilder) Shared(name string) Builder {
if name == "" {
panic("resource name could not be empty")
}

t.prefix = t.prefix + name
t.shs = append(t.shs, t.prefix)

return t
}

func (t *stackedBuilder) Exclusive(name string) Builder {
if name == "" {
panic("resource name could not be empty")
}

t.prefix = t.prefix + name
t.exs = append(t.exs, t.prefix)

Expand Down
7 changes: 7 additions & 0 deletions stl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ func TestExclusiveAndSharedInParallelWithDiffExclusiveAndSameShared(t *testing.T
require.True(t, stats[0].Duration < Dur+time.Millisecond*20 && stats[0].Duration > Dur)
}

func TestEmptyResourceNames(t *testing.T) {
require.Panics(t, func() { NewStacked().Shared("") })
require.Panics(t, func() { NewStacked().Exclusive("") })
require.Panics(t, func() { New().Shared("") })
require.Panics(t, func() { New().Exclusive("") })
}

func TestStacked(t *testing.T) {
const Dur = time.Millisecond * 100
bc := bottleneck.NewCalculator()
Expand Down

0 comments on commit bf0a5c3

Please sign in to comment.