From 6a8bf9ae0a286f2abc1632bb9a13a653e07e8040 Mon Sep 17 00:00:00 2001 From: spiddy Date: Sun, 21 Jun 2015 12:29:48 +0200 Subject: [PATCH] fixes #9 Implement global filter --- captain/captain.go | 15 ++++++--------- captain/cmd.go | 21 ++++++++++++++------- captain/config_test.go | 4 ++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/captain/captain.go b/captain/captain.go index 707f621..33f67df 100644 --- a/captain/captain.go +++ b/captain/captain.go @@ -16,7 +16,7 @@ func RealMain() { } // Pre function executes commands on pre section before build -func Pre(config Config, filter string) { +func Pre(config Config) { for _, value := range config.GetPreCommands() { info("Running pre command: %s", value) res := execute("bash", "-c", value) @@ -28,7 +28,7 @@ func Pre(config Config, filter string) { } // Post function executes commands on pre section after build -func Post(config Config, filter string) { +func Post(config Config) { for _, value := range config.GetPostCommands() { info("Running post command: %s", value) res := execute("bash", "-c", value) @@ -40,13 +40,10 @@ func Post(config Config, filter string) { } // Build function compiles the Containers of the project -func Build(config Config, filter string) { - Pre(config, filter) +func Build(config Config) { + Pre(config) var images = config.GetImageNames() - if filter != "" { - images = filterImages(images, filter) - } var rev = getRevision() // Sort keys to iterate them deterministically @@ -125,7 +122,7 @@ func Build(config Config, filter string) { } // Test function executes the tests of the project -func Test(config Config, filter string) { +func Test(config Config) { for _, value := range config.GetUnitTestCommands() { info("Running unit test command: %s", value) res := execute("bash", "-c", value) @@ -137,7 +134,7 @@ func Test(config Config, filter string) { } // Push function pushes the containers to the remote registry -func Push(config Config, filter string) { +func Push(config Config) { // If no Git repo exist if !isGit() { err("No local git repository found, cannot push") diff --git a/captain/cmd.go b/captain/cmd.go index 5ca10ad..25a7dfc 100644 --- a/captain/cmd.go +++ b/captain/cmd.go @@ -27,12 +27,11 @@ func handleCmd() { Run: func(cmd *cobra.Command, args []string) { config := NewConfig(options, true) - var images string if len(args) == 1 { - images = args[0] + config.FilterConfig(args[0]) } - Build(config, images) + Build(config) }, } @@ -43,9 +42,13 @@ func handleCmd() { Run: func(cmd *cobra.Command, args []string) { config := NewConfig(options, true) + if len(args) == 1 { + config.FilterConfig(args[0]) + } + // Build everything before testing - Build(config, "") - Test(config, "") + Build(config) + Test(config) }, } @@ -56,9 +59,13 @@ func handleCmd() { Run: func(cmd *cobra.Command, args []string) { config := NewConfig(options, true) + if len(args) == 1 { + config.FilterConfig(args[0]) + } + // Build everything before pushing - Build(config, "") - Push(config, "") + Build(config) + Push(config) }, } diff --git a/captain/config_test.go b/captain/config_test.go index 07aaf61..d395ccc 100644 --- a/captain/config_test.go +++ b/captain/config_test.go @@ -39,9 +39,9 @@ func TestGetImageNames(t *testing.T) { } func TestGetUnitTestCommands(t *testing.T) { - options.config = "../captain.yml" + options.config = "test/Simple/captain.yml" c := NewConfig(options,false) - expected := []string{"docker run harbur/captain-test go test github.com/harbur/captain/captain"} + expected := []string{"echo testing 1 web", "echo testing 2 web", "echo testing 1 backend", "echo testing 2 backend"} assert.Equal(t,expected, c.GetUnitTestCommands(), "Should return unit tests") }