Skip to content

Commit

Permalink
fixes #9 Implement global filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dkapanidis committed Jun 21, 2015
1 parent 4b533f0 commit 6a8bf9a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
15 changes: 6 additions & 9 deletions captain/captain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down
21 changes: 14 additions & 7 deletions captain/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand All @@ -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)
},
}

Expand All @@ -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)
},
}

Expand Down
4 changes: 2 additions & 2 deletions captain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 6a8bf9a

Please sign in to comment.