From 776c4ca54927d5bb442d6a46e460f87cbfc04ba5 Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Sat, 1 Mar 2014 14:45:39 -0800 Subject: [PATCH] `allup test` runs the specified test command --- .allup | 5 ++++ features/couchdb.feature | 6 ++--- features/development_commands.feature | 12 +++++++++ features/step_definitions/http_steps.rb | 5 ++-- features/support/env.rb | 9 +++++-- src/main/main.go | 36 +++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 .allup create mode 100644 features/development_commands.feature diff --git a/.allup b/.allup new file mode 100644 index 0000000..2909aa4 --- /dev/null +++ b/.allup @@ -0,0 +1,5 @@ +{ + "commands": { + "test": "GOPATH=`pwd` go test allup" + } +} diff --git a/features/couchdb.feature b/features/couchdb.feature index 395e768..045723a 100644 --- a/features/couchdb.feature +++ b/features/couchdb.feature @@ -2,11 +2,11 @@ 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"}} """ @@ -14,7 +14,7 @@ Feature: validating couchdb installation 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" diff --git a/features/development_commands.feature b/features/development_commands.feature new file mode 100644 index 0000000..3be714d --- /dev/null +++ b/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" diff --git a/features/step_definitions/http_steps.rb b/features/step_definitions/http_steps.rb index bd606af..8a0c8e5 100644 --- a/features/step_definitions/http_steps.rb +++ b/features/step_definitions/http_steps.rb @@ -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| diff --git a/features/support/env.rb b/features/support/env.rb index 88b8cfc..0812d75 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -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..." @@ -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 diff --git a/src/main/main.go b/src/main/main.go index 6cc4dc4..4734ac7 100644 --- a/src/main/main.go +++ b/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() { @@ -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) }