diff options
Diffstat (limited to 'adapters/bash/config.go')
-rw-r--r-- | adapters/bash/config.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/adapters/bash/config.go b/adapters/bash/config.go new file mode 100644 index 0000000..aaa405a --- /dev/null +++ b/adapters/bash/config.go @@ -0,0 +1,64 @@ +package bash + +import ( + "log" + "golang.flu0r1ne.net/planr" + "github.com/BurntSushi/toml" +) + +const ( + DEFAULT_TIMEOUT=1000 +) + +type Defaults struct { + Testfile string + Timeout uint +} + +func (child *Defaults) Inherit(p interface{}) { + parent := p.(*Defaults) + + if(child.Timeout == 0) { child.Timeout = parent.Timeout } +} + +type Config struct { + Defaults +} + +func (c *Config) finalize(path string) { + if c.Testfile == "" { + log.Fatalf("\"Testfile\" is not defined for unit %s\n", path) + } + + if c.Timeout == 0 { + c.Timeout = DEFAULT_TIMEOUT; + } +} + +func finalizeConfigs(tcs []planr.TestCase) { + for i := range tcs { + cfg := tcs[i].AdapterConfig().(*Config) + + cfg.finalize(tcs[i].Path) + } +} + +func ParseConfig(prim toml.Primitive) (planr.InheritableConfig, error) { + config := Config {} + + if err := toml.PrimitiveDecode(prim, &config); err != nil { + return nil, err + } + + return &config, nil +} + +func ParseDefaultConfig(prim toml.Primitive) (planr.InheritableConfig, error) { + config := Defaults{} + + if err := toml.PrimitiveDecode(prim, &config); err != nil { + return nil, err + } + + return &config, nil +} |