Commit b5f4ffa5 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

template: OnlyExcept skipping

parent c12072ec
......@@ -125,6 +125,31 @@ func (t *Template) Validate() error {
return err
}
// Skip says whether or not to skip the build with the given name.
func (o *OnlyExcept) Skip(n string) bool {
if len(o.Only) > 0 {
for _, v := range o.Only {
if v == n {
return false
}
}
return true
}
if len(o.Except) > 0 {
for _, v := range o.Except {
if v == n {
return true
}
}
return false
}
return false
}
// Validate validates that the OnlyExcept settings are correct for a thing.
func (o *OnlyExcept) Validate(t *Template) error {
if len(o.Only) > 0 && len(o.Except) > 0 {
......
......@@ -92,3 +92,46 @@ func TestTemplateValidate(t *testing.T) {
}
}
}
func TestOnlyExceptSkip(t *testing.T) {
cases := []struct {
Only, Except []string
Input string
Result bool
}{
{
[]string{"foo"},
nil,
"foo",
false,
},
{
nil,
[]string{"foo"},
"foo",
true,
},
{
nil,
nil,
"foo",
false,
},
}
for _, tc := range cases {
oe := &OnlyExcept{
Only: tc.Only,
Except: tc.Except,
}
actual := oe.Skip(tc.Input)
if actual != tc.Result {
t.Fatalf(
"bad: %#v\n\n%#v\n\n%#v\n\n%#v",
actual, tc.Only, tc.Except, tc.Input)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment