aboutsummaryrefslogtreecommitdiff
path: root/adapters/bash/config.go
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 04:30:33 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 04:30:33 -0500
commit62e85f40923b3485ba60766052de7150acf039c5 (patch)
treebb9e59fa8af4bb95721928c5fc787a4ae3c422c2 /adapters/bash/config.go
parenta6f45bfa932b9e8e2393b5643e2bc38e44ba76df (diff)
downloadplanr-62e85f40923b3485ba60766052de7150acf039c5.tar.xz
planr-62e85f40923b3485ba60766052de7150acf039c5.zip
Add bash adapter
Diffstat (limited to 'adapters/bash/config.go')
-rw-r--r--adapters/bash/config.go64
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
+}