Skip to content

Commit

Permalink
feat: add option features to skip tests (#210)
Browse files Browse the repository at this point in the history
This change adds features map to option for skipping unsupported tests
based on supported features.

Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez authored Dec 28, 2024
1 parent ede5fbf commit 5f437eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions option/modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ func Env(env []string) Modifier {
o.env = env
})
}

// WithNoEnvironmentVariablePassthrough denotes the option does not support environment variable passthrough.
//
// This is useful for disabling tests that require this feature.
func WithNoEnvironmentVariablePassthrough() Modifier {
return newFuncModifier(func(o *Option) {
delete(o.features, environmentVariablePassthrough)
})
}
20 changes: 17 additions & 3 deletions option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ import (
"strings"
)

type feature int

const (
environmentVariablePassthrough feature = iota
)

// Option customizes how tests are run.
//
// If a testing function needs special customizations other than the ones specified in Option,
// we can use composition to extend it.
// For example, to test login functionality,
// we may create a struct named LoginOption that embeds Option and contains additional fields like Username and Password.
type Option struct {
subject []string
env []string
subject []string
env []string
features map[feature]bool
}

// New does some sanity checks on the arguments before initializing an Option.
Expand All @@ -36,7 +43,7 @@ func New(subject []string, modifiers ...Modifier) (*Option, error) {
return nil, errors.New("missing subject")
}

o := &Option{subject: subject}
o := &Option{subject: subject, features: map[feature]bool{environmentVariablePassthrough: true}}
for _, modifier := range modifiers {
modifier.modify(o)
}
Expand Down Expand Up @@ -80,3 +87,10 @@ func containsEnv(envs []string, targetEnvKey string) (int, bool) {

return -1, false
}

// SupportsEnvVarPassthrough is used by tests to check if the option
// supports [feature.environmentVariablePassthrough].
func (o *Option) SupportsEnvVarPassthrough() bool {
support, ok := o.features[environmentVariablePassthrough]
return ok && support
}
4 changes: 4 additions & 0 deletions tests/compose_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func ComposeBuild(o *option.Option) {
})

ginkgo.It("should build services defined in the compose file specified by the COMPOSE_FILE environment variable", func() {
if !o.SupportsEnvVarPassthrough() {
ginkgo.Skip("Test requires option environment variable passthrough")
}

envKey := "COMPOSE_FILE"
o.UpdateEnv(envKey, composeFilePath)

Expand Down

0 comments on commit 5f437eb

Please sign in to comment.