Skip to content

Commit

Permalink
Add teststep.Config interface so that logic that examines the content…
Browse files Browse the repository at this point in the history
…s of TestStep.Config or TestStep.Directory can be encapsulated in teststep.config struct (#150)
  • Loading branch information
bendbennett committed Jul 17, 2023
1 parent 0b590e7 commit 91b0ce7
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/teststep/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package teststep

import (
"fmt"
"strings"
)

type Config interface {
HasConfiguration() bool
}

type configuration struct {
raw string
directory string
file string
}

func Configuration(raw, directory string) (configuration, error) {
var populatedConfig []string

if raw != "" {
populatedConfig = append(populatedConfig, fmt.Sprintf("%q", "raw"))
}

if directory != "" {
populatedConfig = append(populatedConfig, fmt.Sprintf("%q", "directory"))
}

if len(populatedConfig) > 1 {
return configuration{}, fmt.Errorf(
"both %s are populated, only one configuration option is allowed",
strings.Join(populatedConfig, " and "),
)
}

return configuration{
raw: raw,
directory: directory,
}, nil
}

func (c configuration) HasConfiguration() bool {
if c.raw != "" {
return true
}

// TODO: do we need to read each file in directory and check that it's not empty.
// TODO: do we also need to verify that it's valid TF config
if c.directory != "" {
return true
}

return false
}

0 comments on commit 91b0ce7

Please sign in to comment.