Skip to content

Commit

Permalink
allup test runs the specified test command
Browse files Browse the repository at this point in the history
  • Loading branch information
avh4 committed Mar 1, 2014
1 parent 959764c commit 776c4ca
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .allup
@@ -0,0 +1,5 @@
{
"commands": {
"test": "GOPATH=`pwd` go test allup"
}
}
6 changes: 3 additions & 3 deletions features/couchdb.feature
Expand Up @@ -2,19 +2,19 @@ Feature: validating couchdb installation
Background:
Given my allup file contains:
"""
{ couchdb: true }
{ "couchdb": true }
"""

Scenario: couchdb is ready to go
Given GET "http://localhost:5984" responds:
Given GET "http://localhost:5984/" responds:
"""
{"couchdb":"Welcome","uuid":"00000000000000000000000000000000","version":"1.5.0","vendor":{"version":"1.5.0-1","name":"Homebrew"}}
"""
When I run `allup`
Then the output should contain "couchdb: OK"

Scenario: no couchdb on the expected port
Given GET "http://localhost:5984" does not connect
Given GET "http://localhost:5984/" does not connect
When I run `allup`
Then the output should contain "couchdb: not running on port 5984"
And the output should contain "brew install couchdb"
Expand Down
12 changes: 12 additions & 0 deletions features/development_commands.feature
@@ -0,0 +1,12 @@
Feature: Development commands
In order to work on a new project
As a new contributor
I want to be able to perform standard commands on the project

Scenario: Run tests
Given my allup file contains:
"""
{ "commands": { "test": "echo 'TE''ST'" } }
"""
When I run `allup test`
Then the output should contain "TEST"
5 changes: 3 additions & 2 deletions features/step_definitions/http_steps.rb
Expand Up @@ -6,8 +6,9 @@
HTTParty.delete("#{CONTROL}")
end

Given(/^GET "http:\/\/localhost:([0-9]*)(\/.*?)" responds:$/) do |port, path, string|
HTTParty.post('#{CONTROL}/http/#{port}/get/#{path}', body: string)
Given(/^GET "http:\/\/localhost:([0-9]*)\/(.*?)" responds:$/) do |port, path, string|
response = HTTParty.post("#{CONTROL}/http/#{port}/get/#{path}", body: string)
response.code.should == 200
end

Given(/^GET "http:\/\/localhost:([0-9]*).*?" does not connect$/) do |port|
Expand Down
9 changes: 7 additions & 2 deletions features/support/env.rb
Expand Up @@ -7,15 +7,19 @@

require 'httparty'

def is_netlocal_running
def is_running(url)
begin
HTTParty.get("http://localhost:9999")
HTTParty.get(url)
return true
rescue Errno::ECONNREFUSED
return false
end
end

def is_netlocal_running
is_running("http://localhost:9999")
end

if !is_netlocal_running
puts "Netlocal is not running. Please start it on localhost:9999"
print "Waiting for you to start netlocal..."
Expand All @@ -26,6 +30,7 @@ def is_netlocal_running
puts
end

fail "===> CouchDB must not be running on port 5984" if is_running("http://localhost:5984")


Before do
Expand Down
36 changes: 36 additions & 0 deletions src/main/main.go
@@ -1,10 +1,12 @@
package main

import (
"encoding/json"
"fmt"
"github.com/codegangsta/cli"
"net/http"
"os"
"os/exec"
)

func main() {
Expand All @@ -24,6 +26,40 @@ func main() {
fmt.Println("couchdb: OK")
}
}
app.Commands = []cli.Command{
{
Name: "test",
Usage: "Run tests",
Action: func(c *cli.Context) {
allupFile, err := os.Open(".allup")
if err != nil {
println(err)
return
}
var settings struct {
Couchdb bool
Commands struct {
Test string
}
}
jsonParser := json.NewDecoder(allupFile)
err = jsonParser.Decode(&settings)
if err != nil {
fmt.Println(err)
return
}

cmd := exec.Command("sh", "-xc", settings.Commands.Test)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
fmt.Println(err)
return
}
},
},
}

app.Run(os.Args)
}

0 comments on commit 776c4ca

Please sign in to comment.