Skip to content

Commit

Permalink
Beginning of functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Buhrietoe committed Dec 7, 2016
1 parent 435b971 commit f7c6fe6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
50 changes: 50 additions & 0 deletions functional/functional_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package functional

import (
"log"
"net"
"net/http"
"testing"
"time"

"github.com/Buhrietoe/brood/server"
)

func startTestServer() (address string) {
// Build web server
serv := server.BuildServer()

// Find an open port
listenSocket, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatalf("could not create socket for server: %s\n", err)
}
err = listenSocket.Close()
if err != nil {
log.Fatalf("could not close socker for server: %s\n", err)
}
log.Printf("found available port: %s\n", listenSocket.Addr().String())

log.Printf("listening on %v\n", listenSocket.Addr().String())
go func() {
err := serv.Run(listenSocket.Addr().String())
if err != nil {
log.Fatalln(err)
}
}()

// It might take time to bind server socket
time.Sleep(time.Second)
return listenSocket.Addr().String()
}

func TestServerHealth(t *testing.T) {
listenAddress := "http://" + startTestServer() + "/ping"
result, err := http.Get(listenAddress)
if err != nil {
t.Error(err)
}
if result.StatusCode != 200 {
t.Errorf("expected 200, got %v", result.StatusCode)
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {
serv := server.BuildServer()
log.Printf("listening on %v\n", config.Server.ListenString)
if serverError := serv.Run(config.Server.ListenString); serverError != nil {
log.Printf("shit broke: %v\n", serverError)
log.Printf("server error: %v\n", serverError)
}
}
}
2 changes: 0 additions & 2 deletions server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ func TestLoadConfig(t *testing.T) {
os.Setenv("BROOD_ADDRESS", "127.0.0.1")
os.Setenv("BROOD_PORT", "1234")

//var config BroodConfig
//config.LoadConfig("")
testConfig, _ := LoadConfig("")

if testConfig.Server.ListenString != "127.0.0.1:1234" {
Expand Down

0 comments on commit f7c6fe6

Please sign in to comment.