Skip to content

Commit

Permalink
Merge branch 'fix-lb-test' into 'master'
Browse files Browse the repository at this point in the history
Address broken tests

Closes #46

See merge request !29
  • Loading branch information
hibooboo2 committed May 30, 2017
2 parents 04008c7 + 31b4ac4 commit 2518898
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 46 deletions.
6 changes: 3 additions & 3 deletions api/datastore/internal/datastoretest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func Test(t *testing.T, ds models.Datastore) {
// unchanged
AppName: testRoute.AppName,
Path: testRoute.Path,
Image: "treeder/hello",
Image: "funcy/hello",
Type: "sync",
Format: "http",
// updated
Expand Down Expand Up @@ -317,7 +317,7 @@ func Test(t *testing.T, ds models.Datastore) {
// unchanged
AppName: testRoute.AppName,
Path: testRoute.Path,
Image: "treeder/hello",
Image: "funcy/hello",
Type: "sync",
Format: "http",
Timeout: 100,
Expand Down Expand Up @@ -482,7 +482,7 @@ var testApp = &models.App{
var testRoute = &models.Route{
AppName: testApp.Name,
Path: "/test",
Image: "treeder/hello",
Image: "funcy/hello",
Type: "sync",
Format: "http",
}
2 changes: 1 addition & 1 deletion api/runner/drivers/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (f *taskDockerTest) EnvVars() map[string]string {
func (f *taskDockerTest) Labels() map[string]string { return nil }
func (f *taskDockerTest) Id() string { return f.id }
func (f *taskDockerTest) Group() string { return "" }
func (f *taskDockerTest) Image() string { return "treeder/hello" }
func (f *taskDockerTest) Image() string { return "funcy/hello" }
func (f *taskDockerTest) Timeout() time.Duration { return 30 * time.Second }
func (f *taskDockerTest) Logger() (stdout, stderr io.Writer) { return f.output, nil }
func (f *taskDockerTest) WriteStat(drivers.Stat) { /* TODO */ }
Expand Down
8 changes: 4 additions & 4 deletions api/runner/drivers/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ func TestDecimate(t *testing.T) {

func TestParseImage(t *testing.T) {
cases := map[string][]string{
"treeder/hello": {"", "treeder/hello", "latest"},
"treeder/hello:v1": {"", "treeder/hello", "v1"},
"funcy/hello": {"", "funcy/hello", "latest"},
"funcy/hello:v1": {"", "funcy/hello", "v1"},
"my.registry/hello": {"my.registry", "hello", "latest"},
"my.registry/hello:v1": {"my.registry", "hello", "v1"},
"mongo": {"", "library/mongo", "latest"},
"mongo:v1": {"", "library/mongo", "v1"},
"quay.com/treeder/hello": {"quay.com", "treeder/hello", "latest"},
"quay.com:8080/treeder/hello:v2": {"quay.com:8080", "treeder/hello", "v2"},
"quay.com/funcy/hello": {"quay.com", "funcy/hello", "latest"},
"quay.com:8080/funcy/hello:v2": {"quay.com:8080", "funcy/hello", "v2"},
"localhost.localdomain:5000/samalba/hipache:latest": {"localhost.localdomain:5000", "samalba/hipache", "latest"},
}

Expand Down
4 changes: 2 additions & 2 deletions api/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestRunnerHello(t *testing.T) {
expectedOut string
expectedErr string
}{
{&models.Route{Image: "treeder/hello"}, ``, "success", "Hello World!", ""},
{&models.Route{Image: "treeder/hello"}, `{"name": "test"}`, "success", "Hello test!", ""},
{&models.Route{Image: "funcy/hello"}, ``, "success", "Hello World!", ""},
{&models.Route{Image: "funcy/hello"}, `{"name": "test"}`, "success", "Hello test!", ""},
} {
var stdout, stderr bytes.Buffer
cfg := &task.Config{
Expand Down
10 changes: 5 additions & 5 deletions api/server/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func TestRouteCreate(t *testing.T) {
{datastore.NewMock(), "/v1/apps/a/routes", `{ "path": "/myroute" }`, http.StatusBadRequest, models.ErrRoutesMissingNew},
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { } }`, http.StatusBadRequest, models.ErrRoutesValidationMissingPath},
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { "path": "/myroute" } }`, http.StatusBadRequest, models.ErrRoutesValidationMissingImage},
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { "image": "treeder/hello" } }`, http.StatusBadRequest, models.ErrRoutesValidationMissingPath},
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { "image": "treeder/hello", "path": "myroute" } }`, http.StatusBadRequest, models.ErrRoutesValidationInvalidPath},
{datastore.NewMock(), "/v1/apps/$/routes", `{ "route": { "image": "treeder/hello", "path": "/myroute" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName},
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { "image": "funcy/hello" } }`, http.StatusBadRequest, models.ErrRoutesValidationMissingPath},
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { "image": "funcy/hello", "path": "myroute" } }`, http.StatusBadRequest, models.ErrRoutesValidationInvalidPath},
{datastore.NewMock(), "/v1/apps/$/routes", `{ "route": { "image": "funcy/hello", "path": "/myroute" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName},

// success
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { "image": "treeder/hello", "path": "/myroute" } }`, http.StatusOK, nil},
{datastore.NewMock(), "/v1/apps/a/routes", `{ "route": { "image": "funcy/hello", "path": "/myroute" } }`, http.StatusOK, nil},
} {
rnr, cancel := testRunner(t)
srv := testServer(test.mock, &mqs.Mock{}, rnr, tasks)
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestRouteUpdate(t *testing.T) {
Path: "/myroute/do",
},
},
), "/v1/apps/a/routes/myroute/do", `{ "route": { "image": "treeder/hello" } }`, http.StatusOK, nil},
), "/v1/apps/a/routes/myroute/do", `{ "route": { "image": "funcy/hello" } }`, http.StatusOK, nil},

// Addresses #381
{datastore.NewMockInit(nil,
Expand Down
4 changes: 2 additions & 2 deletions api/server/runner_async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func TestRouteRunnerAsyncExecution(t *testing.T) {
{Name: "myapp", Config: map[string]string{"app": "true"}},
},
[]*models.Route{
{Type: "async", Path: "/myroute", AppName: "myapp", Image: "treeder/hello", Config: map[string]string{"test": "true"}},
{Type: "async", Path: "/myroute", AppName: "myapp", Image: "funcy/hello", Config: map[string]string{"test": "true"}},
{Type: "async", Path: "/myerror", AppName: "myapp", Image: "funcy/error", Config: map[string]string{"test": "true"}},
{Type: "async", Path: "/myroute/:param", AppName: "myapp", Image: "treeder/hello", Config: map[string]string{"test": "true"}},
{Type: "async", Path: "/myroute/:param", AppName: "myapp", Image: "funcy/hello", Config: map[string]string{"test": "true"}},
},
)
mq := &mqs.Mock{}
Expand Down
2 changes: 1 addition & 1 deletion api/server/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestRouteRunnerExecution(t *testing.T) {
{Name: "myapp", Config: models.Config{}},
},
[]*models.Route{
{Path: "/myroute", AppName: "myapp", Image: "treeder/hello", Headers: map[string][]string{"X-Function": {"Test"}}},
{Path: "/myroute", AppName: "myapp", Image: "funcy/hello", Headers: map[string][]string{"X-Function": {"Test"}}},
{Path: "/myerror", AppName: "myapp", Image: "funcy/error", Headers: map[string][]string{"X-Function": {"Test"}}},
},
), &mqs.Mock{}, rnr, tasks)
Expand Down
2 changes: 1 addition & 1 deletion api/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestFullStack(t *testing.T) {
{"create my app", "POST", "/v1/apps", `{ "app": { "name": "myapp" } }`, http.StatusOK, 0},
{"list apps", "GET", "/v1/apps", ``, http.StatusOK, 0},
{"get app", "GET", "/v1/apps/myapp", ``, http.StatusOK, 0},
{"add myroute", "POST", "/v1/apps/myapp/routes", `{ "route": { "name": "myroute", "path": "/myroute", "image": "treeder/hello" } }`, http.StatusOK, 1},
{"add myroute", "POST", "/v1/apps/myapp/routes", `{ "route": { "name": "myroute", "path": "/myroute", "image": "funcy/hello" } }`, http.StatusOK, 1},
{"add myroute2", "POST", "/v1/apps/myapp/routes", `{ "route": { "name": "myroute2", "path": "/myroute2", "image": "funcy/error" } }`, http.StatusOK, 2},
{"get myroute", "GET", "/v1/apps/myapp/routes/myroute", ``, http.StatusOK, 2},
{"get myroute2", "GET", "/v1/apps/myapp/routes/myroute2", ``, http.StatusOK, 2},
Expand Down
2 changes: 1 addition & 1 deletion api/server/special_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestSpecialHandlerSet(t *testing.T) {
// {Name: "test"},
// },
// Routes: []*models.Route{
// {Path: "/test", Image: "treeder/hello", AppName: "test"},
// {Path: "/test", Image: "funcy/hello", AppName: "test"},
// },
// },
// MQ: &mqs.Mock{},
Expand Down
4 changes: 2 additions & 2 deletions docs/definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Note: Route level configuration overrides app level configuration.
Using `fn`:

```sh
fn routes create myapp /path --config k1=v1 --config k2=v2 --image treeder/hello
fn routes create myapp /path --config k1=v1 --config k2=v2 --image funcy/hello
```

Or using cURL:
Expand All @@ -80,7 +80,7 @@ curl -H "Content-Type: application/json" -X POST -d '{
```json
{
"path": "/hello",
"image": "treeder/hello",
"image": "funcy/hello",
"type": "sync",
"memory": 128,
"config": {
Expand Down
2 changes: 1 addition & 1 deletion docs/function-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The files can be named as:
An example of a function file:

```yaml
name: treeder/hello
name: funcy/hello
version: 0.0.1
type: sync
memory: 128
Expand Down
8 changes: 4 additions & 4 deletions docs/operating/docker-swarm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ $ export FUNCTIONS=$(docker port functions | cut -d ' ' -f3)
$ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' http://$FUNCTIONS/v1/apps
{"message":"App successfully created","app":{"name":"myapp","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"treeder/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"treeder/hello","memory":128,"type":"sync","config":null}}
$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"funcy/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"funcy/hello","memory":128,"type":"sync","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' http://$FUNCTIONS/r/myapp/hello-sync
Hello Johnny!
Expand Down Expand Up @@ -125,8 +125,8 @@ $ export FUNCTIONS=$(docker port functions-lb | cut -d ' ' -f3)
$ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' http://$FUNCTIONS/v1/apps
{"message":"App successfully created","app":{"name":"myapp","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"treeder/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"treeder/hello","memory":128,"type":"sync","config":null}}
$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"funcy/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"funcy/hello","memory":128,"type":"sync","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' http://$FUNCTIONS/r/myapp/hello-sync
Hello Johnny!
Expand Down
8 changes: 4 additions & 4 deletions docs/operating/kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ $ export FUNCTIONS=$(kubectl get -o json svc functions | jq -r '.status.loadBala
$ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' http://$FUNCTIONS/v1/apps
{"message":"App successfully created","app":{"name":"myapp","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"treeder/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"treeder/hello","memory":128,"type":"sync","config":null}}
$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"funcy/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"funcy/hello","memory":128,"type":"sync","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' http://$FUNCTIONS/r/myapp/hello-sync
Hello Johnny!
Expand Down Expand Up @@ -102,8 +102,8 @@ $ export FUNCTIONS=$(kubectl get -o json svc functions | jq -r '.status.loadBala
$ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' http://$FUNCTIONS/v1/apps
{"message":"App successfully created","app":{"name":"myapp","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"treeder/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"treeder/hello","memory":128,"type":"sync","config":null}}
$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"funcy/hello" } }' http://$FUNCTIONS/v1/apps/myapp/routes
{"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"funcy/hello","memory":128,"type":"sync","config":null}}

$ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' http://$FUNCTIONS/r/myapp/hello-sync
Hello Johnny!
Expand Down
2 changes: 1 addition & 1 deletion docs/operating/routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ some container configuration values.
curl -H "Content-Type: application/json" -X POST -d '{
"route": {
"path":"/hello",
"image":"treeder/hello",
"image":"funcy/hello",
"memory": 100,
"type": "sync",
"config": {"APPLOG": "stderr"}
Expand Down
8 changes: 4 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ Now that we have an app, we can route endpoints to functions.
### Add a Route

A route is a way to define a path in your application that maps to a function. In this example, we'll map
`/hello` to a simple `Hello World!` function called `treeder/hello` which is a function we already made that you
`/hello` to a simple `Hello World!` function called `funcy/hello` which is a function we already made that you
can use -- yes, you can share functions! The source code for this function is in the [examples directory](examples/hello/go).
You can read more about [writing your own functions here](docs/writing.md).

```sh
fn routes create myapp /hello -i treeder/hello
fn routes create myapp /hello -i funcy/hello
```

Or using cURL:
Expand All @@ -39,7 +39,7 @@ Or using cURL:
curl -H "Content-Type: application/json" -X POST -d '{
"route": {
"path":"/hello",
"image":"treeder/hello"
"image":"funcy/hello"
}
}' http://localhost:8080/v1/apps/myapp/routes
```
Expand Down Expand Up @@ -101,7 +101,7 @@ curl -H "Content-Type: application/json" -X POST -d '{
"route": {
"type": "async",
"path":"/hello-async",
"image":"treeder/hello"
"image":"funcy/hello"
}
}' http://localhost:8080/v1/apps/myapp/routes
```
Expand Down
2 changes: 1 addition & 1 deletion examples/blog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A simple serverless blog API
USERNAME=YOUR_DOCKER_HUB_USERNAME
# build it
docker run --rm -v "$PWD":/go/src/github.com/treeder/hello -w /go/src/github.com/treeder/hello funcy/go:dev go build -o function
docker run --rm -v "$PWD":/go/src/github.com/funcy/hello -w /go/src/github.com/funcy/hello funcy/go:dev go build -o function
docker build -t $USERNAME/func-blog .
```

Expand Down
16 changes: 8 additions & 8 deletions fn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ otherapp

$ fn routes list myapp # list routes of an app
path image
/hello treeder/hello
/hello funcy/hello

$ fn routes create otherapp /hello treeder/hello # create route
/hello created with treeder/hello
$ fn routes create otherapp /hello funcy/hello # create route
/hello created with funcy/hello

$ fn routes delete otherapp hello # delete route
/hello deleted
Expand Down Expand Up @@ -111,15 +111,15 @@ choices are: `memory`, `type` and `config`.
Thus a more complete example of route creation will look like:
```sh
fn routes create --memory 256 --type async --config DB_URL=http://example.org/ otherapp /hello treeder/hello
fn routes create --memory 256 --type async --config DB_URL=http://example.org/ otherapp /hello funcy/hello
```
You can also update existent routes configurations using the command `fn routes update`
For example:
```sh
fn routes update --memory 64 --type sync --image treeder/hello
fn routes update --memory 64 --type sync --image funcy/hello
```
To know exactly what configurations you can update just use the command
Expand Down Expand Up @@ -195,7 +195,7 @@ $ fn test --remote myapp
### Creating a new function from source
```
fn init treeder/hello --runtime ruby
fn init funcy/hello --runtime ruby
fn deploy myapp /hello
```
Expand All @@ -206,7 +206,7 @@ fn deploy myapp (discover route path if available in func.yaml)
### Testing function locally
```
fn run treeder/hello
fn run funcy/hello
```
### Testing route
Expand All @@ -225,7 +225,7 @@ fn apps delete myapp
### Route management
```
fn routes create myapp /hello treeder/hello
fn routes create myapp /hello funcy/hello
# routes update will also update any changes in the func.yaml file too.
fn routes update myapp /hello --timeout 30 --type async
fn routes config set myapp /hello log_level info
Expand Down
5 changes: 4 additions & 1 deletion lb/lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func TestCHGet(t *testing.T) {

keys := []string{"a", "b", "c"}
for _, k := range keys {
_ = ch.get(k)
_, err := ch.get(k)
if err != nil {
t.Fatal("CHGet returned an error: ", err)
}
// testing this doesn't panic basically? could test distro but meh
}
}

0 comments on commit 2518898

Please sign in to comment.