Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option features to skip tests #210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading