From 2cf112c0ba4dbdaed4f7cb00fc273e81231f7efa Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 22 Aug 2013 11:34:51 -0700 Subject: [PATCH] common/command: more tests for filtering builds --- common/command/template_test.go | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/common/command/template_test.go b/common/command/template_test.go index d7db9f151..b5cdd1a70 100644 --- a/common/command/template_test.go +++ b/common/command/template_test.go @@ -41,6 +41,42 @@ func TestBuildOptionsBuilds(t *testing.T) { } } +func TestBuildOptionsBuilds_except(t *testing.T) { + opts := new(BuildOptions) + opts.Except = []string{"foo"} + + bs, err := opts.Builds(testTemplate()) + if err != nil { + t.Fatalf("err: %s", err) + } + + if len(bs) != 1 { + t.Fatalf("bad: %d", len(bs)) + } + + if bs[0].Name() != "bar" { + t.Fatalf("bad: %s", bs[0].Name()) + } +} + +func TestBuildOptionsBuilds_only(t *testing.T) { + opts := new(BuildOptions) + opts.Only = []string{"foo"} + + bs, err := opts.Builds(testTemplate()) + if err != nil { + t.Fatalf("err: %s", err) + } + + if len(bs) != 1 { + t.Fatalf("bad: %d", len(bs)) + } + + if bs[0].Name() != "foo" { + t.Fatalf("bad: %s", bs[0].Name()) + } +} + func TestBuildOptionsValidate(t *testing.T) { bf := new(BuildOptions)