Skip to content

Commit

Permalink
Merge pull request #22 from acm-uiuc/testing
Browse files Browse the repository at this point in the history
travis CI unit tests
  • Loading branch information
narendasan authored Nov 22, 2017
2 parents fb63a04 + 193375c commit f727ba3
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 25 deletions.
25 changes: 20 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@ language: go
go:
- 1.8
- 1.8.x
- 1.9
- 1.9.x

sudo: false

jobs:
include:
- stage: build
script:
- go get -u github.com/golang/dep/...
- dep ensure
- go install github.com/acm-uiuc/arbor
- stage: test
script:
- go test -v github.com/acm-uiuc/arbor/tests

stages:
- build
- test

matrix:
allow_failures:
- go: 1.8.x
- go: 1.9.x

script:
- go get -u github.com/golang/dep/...
- dep ensure
- go install github.com/acm-uiuc/arbor

notifications:
email: false
6 changes: 3 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

[[dependencies]]
[[constraint]]
branch = "master"
name = "github.com/gorilla/mux"

[[dependencies]]
[[constraint]]
branch = "master"
name = "github.com/kennygrant/sanitize"

[[dependencies]]
[[constraint]]
branch = "master"
name = "github.com/syndtr/goleveldb"
2 changes: 1 addition & 1 deletion examples/gateway/arbor-example-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ func main() {
//Configure Arbor
gateway.ConfigArbor()
//Register the Routes in a Collection and Boot Arbor
arbor.Boot(gateway.RegisterRoutes(), 8000)
arbor.Boot(gateway.RegisterRoutes(), "0.0.0.0", 8000)
}
2 changes: 1 addition & 1 deletion examples/gateway/product_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

//URL of the Product Service API
const productServiceURL string = "http://localhost:5000"
const productServiceURL string = "http://0.0.0.0:5000"

//Data format of the API
const productServiceFormat string = "JSON"
Expand Down
5 changes: 3 additions & 2 deletions examples/products/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package products

import (
"context"
"encoding/json"
"fmt"
"log"
Expand All @@ -21,7 +22,7 @@ func NewApp() *App {
a.Router = mux.NewRouter()
a.Model = newProductModel()
a.initializeRoutes()
a.Srv = &http.Server{Addr: ":5000", Handler: a.Router}
a.Srv = &http.Server{Addr: "0.0.0.0:5000", Handler: a.Router}
return a
}

Expand All @@ -41,7 +42,7 @@ func (a *App) Run() {

func (a *App) Kill() {
fmt.Println("Killing example service")
a.Srv.Shutdown(nil)
a.Srv.Shutdown(context.Background())
}

func (a *App) initializeRoutes() {
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const help = `Usage: executable [-r | --register-client client_name] [-c | --che
// runs arbor with the security layer
//
// It will start the arbor instance, parsing the command arguments and execute the behavior.
func Boot(routes RouteCollection, port uint16) *server.ArborServer {
func Boot(routes RouteCollection, addr string, port uint16) *server.ArborServer {
var srv *server.ArborServer
if len(os.Args) == 3 && (os.Args[1] == "--register-client" || os.Args[1] == "-r") {
RegisterClient(os.Args[2])
Expand All @@ -63,14 +63,14 @@ func Boot(routes RouteCollection, port uint16) *server.ArborServer {
ListClients()
} else if len(os.Args) == 2 && (os.Args[1] == "--unsecured" || os.Args[1] == "-u") {
logger.Log(logger.WARN, "Starting Arbor in unsecured mode")
srv = server.StartUnsecuredServer(routes.toServiceRoutes(), port)
srv = server.StartUnsecuredServer(routes.toServiceRoutes(), addr, port)
} else if len(os.Args) == 2 && (os.Args[1] == "--help" || os.Args[1] == "-h") {
fmt.Println(help)
} else if len(os.Args) > 1 {
logger.Log(logger.ERR, "Unknown Command")
fmt.Println(help)
} else {
srv = server.StartSecuredServer(routes.toServiceRoutes(), port)
srv = server.StartSecuredServer(routes.toServiceRoutes(), addr, port)
}
return srv
}
Expand Down
17 changes: 9 additions & 8 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"fmt"
"net/http"
"context"

"github.com/acm-uiuc/arbor/logger"
"github.com/acm-uiuc/arbor/security"
Expand All @@ -18,17 +19,17 @@ type ArborServer struct {
}

//NewServer creates a new ArborSever
func NewServer(routes services.RouteCollection, port uint16) *ArborServer {
func NewServer(routes services.RouteCollection, addr string, port uint16) *ArborServer {
a := new(ArborServer)
a.addr = fmt.Sprintf(":%d", port)
a.addr = fmt.Sprintf("%s:%d", addr, port)
a.router = NewRouter(routes)
a.server = &http.Server{Addr: a.addr, Handler: a.router}
return a
}

//StartServer starts the http server in a goroutine to start listening
func (a *ArborServer) StartServer() {
logger.Log(logger.SPEC, "Roots being planted [Server is listening on localhost"+a.addr+"]")
logger.Log(logger.SPEC, "Roots being planted [Server is listening on "+a.addr+"]")

go func() {
err := a.server.ListenAndServe()
Expand All @@ -45,7 +46,7 @@ func (a *ArborServer) StartServer() {
//KillServer ends the http server
func (a *ArborServer) KillServer() {
logger.Log(logger.SPEC, "Pulling up the roots [Shutting down the server...]")
a.server.Shutdown(nil)
a.server.Shutdown(context.Background())
if security.IsEnabled() {
security.Shutdown()
}
Expand All @@ -54,8 +55,8 @@ func (a *ArborServer) KillServer() {
// StartSecuredServer starts a secured arbor server (Token required for access)
//
// Provide a set of routes to serve and a port to serve on.
func StartSecuredServer(routes services.RouteCollection, port uint16) *ArborServer {
srv := NewServer(routes, port)
func StartSecuredServer(routes services.RouteCollection, addr string, port uint16) *ArborServer {
srv := NewServer(routes, addr, port)
security.Init()
srv.StartServer()
return srv
Expand All @@ -64,8 +65,8 @@ func StartSecuredServer(routes services.RouteCollection, port uint16) *ArborServ
// StartUnsecuredServer starts an unsecured arbor server (Token required for access)
//
// Provide a set of routes to server and a port to serve on/
func StartUnsecuredServer(routes services.RouteCollection, port uint16) *ArborServer {
srv := NewServer(routes, port)
func StartUnsecuredServer(routes services.RouteCollection, addr string, port uint16) *ArborServer {
srv := NewServer(routes, addr, port)
srv.StartServer()
return srv
}
6 changes: 4 additions & 2 deletions tests/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/acm-uiuc/arbor/server"
)

const url string = "http://localhost:8000"
const url string = "http://0.0.0.0:8000"

type product struct {
ID int `json:"id"`
Expand All @@ -35,13 +35,15 @@ func newTestingServices() *testingServices {
t.testService = products.NewApp()
t.testService.Run()
gateway.ConfigArbor()
t.testGateway = arbor.Boot(gateway.RegisterRoutes(), 8000)
t.testGateway = arbor.Boot(gateway.RegisterRoutes(), "0.0.0.0", 8000)
time.Sleep(250 * time.Millisecond)
return t
}

func (t *testingServices) killTestingServices() {
t.testGateway.KillServer()
t.testService.Kill()
time.Sleep(250 * time.Millisecond)
}

func TestProxyGETEmpty(t *testing.T) {
Expand Down

0 comments on commit f727ba3

Please sign in to comment.