Skip to content

Commit

Permalink
GH-76: fix config validation
Browse files Browse the repository at this point in the history
Fixes #76
  • Loading branch information
skipor committed Jan 19, 2018
1 parent 965124a commit 51c8f2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import (
)

type Config struct {
Pools []InstancePoolConfig `config:"pools"`
Pools []InstancePoolConfig `config:"pools" validate:"required,dive"`
}

type InstancePoolConfig struct {
Id string
Provider core.Provider `config:"ammo"`
Aggregator core.Aggregator `config:"result"`
NewGun func() (core.Gun, error) `config:"gun"`
Provider core.Provider `config:"ammo" validate:"required"`
Aggregator core.Aggregator `config:"result" validate:"required"`
NewGun func() (core.Gun, error) `config:"gun" validate:"required"`
RPSPerInstance bool `config:"rps-per-instance"`
NewRPSSchedule func() (core.Schedule, error) `config:"rps"`
StartupSchedule core.Schedule `config:"startup"`
NewRPSSchedule func() (core.Schedule, error) `config:"rps" validate:"required"`
StartupSchedule core.Schedule `config:"startup" validate:"required"`
}

// TODO(skipor): use something github.com/rcrowley/go-metrics based.
Expand Down
20 changes: 20 additions & 0 deletions core/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,32 @@ import (

"github.com/yandex/pandora/core"
"github.com/yandex/pandora/core/aggregate"
"github.com/yandex/pandora/core/config"
"github.com/yandex/pandora/core/mocks"
"github.com/yandex/pandora/core/provider"
"github.com/yandex/pandora/core/schedule"
"github.com/yandex/pandora/lib/testutil"
)

var _ = Describe("config validation", func() {
It("dive validation", func() {
conf := Config{
Pools: []InstancePoolConfig{
{},
},
}
err := config.Validate(conf)
Expect(err).To(HaveOccurred())
})

It("pools required", func() {
conf := Config{}
err := config.Validate(conf)
Expect(err).To(HaveOccurred())
})

})

func newTestPoolConf() (InstancePoolConfig, *coremock.Gun) {
gun := &coremock.Gun{}
gun.On("Bind", mock.Anything, mock.Anything).Return(nil)
Expand Down

0 comments on commit 51c8f2f

Please sign in to comment.