-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters