From 31b4ac4516f6e9de9590962ad7ca4f94d1d6264a Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Tue, 30 May 2017 08:50:53 -0700 Subject: [PATCH] Address broken tests --- api/datastore/internal/datastoretest/test.go | 6 +++--- api/runner/drivers/docker/docker_test.go | 2 +- api/runner/drivers/driver_test.go | 8 ++++---- api/runner/runner_test.go | 4 ++-- api/server/routes_test.go | 10 +++++----- api/server/runner_async_test.go | 4 ++-- api/server/runner_test.go | 2 +- api/server/server_test.go | 2 +- api/server/special_handler_test.go | 2 +- docs/definitions.md | 4 ++-- docs/function-file.md | 2 +- docs/operating/docker-swarm/README.md | 8 ++++---- docs/operating/kubernetes/README.md | 8 ++++---- docs/operating/routes.md | 2 +- docs/usage.md | 8 ++++---- examples/blog/README.md | 2 +- fn/README.md | 16 ++++++++-------- lb/lb_test.go | 5 ++++- 18 files changed, 49 insertions(+), 46 deletions(-) diff --git a/api/datastore/internal/datastoretest/test.go b/api/datastore/internal/datastoretest/test.go index 37ff1f972..95621b7e6 100644 --- a/api/datastore/internal/datastoretest/test.go +++ b/api/datastore/internal/datastoretest/test.go @@ -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 @@ -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, @@ -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", } diff --git a/api/runner/drivers/docker/docker_test.go b/api/runner/drivers/docker/docker_test.go index f358a5162..f571a0985 100644 --- a/api/runner/drivers/docker/docker_test.go +++ b/api/runner/drivers/docker/docker_test.go @@ -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 */ } diff --git a/api/runner/drivers/driver_test.go b/api/runner/drivers/driver_test.go index 4099ce2e0..5c9ff6c46 100644 --- a/api/runner/drivers/driver_test.go +++ b/api/runner/drivers/driver_test.go @@ -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"}, } diff --git a/api/runner/runner_test.go b/api/runner/runner_test.go index d6843d30d..578a3272a 100644 --- a/api/runner/runner_test.go +++ b/api/runner/runner_test.go @@ -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{ diff --git a/api/server/routes_test.go b/api/server/routes_test.go index 623901079..5f77c332d 100644 --- a/api/server/routes_test.go +++ b/api/server/routes_test.go @@ -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) @@ -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, diff --git a/api/server/runner_async_test.go b/api/server/runner_async_test.go index aea12267d..224d5e35c 100644 --- a/api/server/runner_async_test.go +++ b/api/server/runner_async_test.go @@ -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{} diff --git a/api/server/runner_test.go b/api/server/runner_test.go index 661e84caa..15a7e2e76 100644 --- a/api/server/runner_test.go +++ b/api/server/runner_test.go @@ -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) diff --git a/api/server/server_test.go b/api/server/server_test.go index 7c7d1da66..0398abf40 100644 --- a/api/server/server_test.go +++ b/api/server/server_test.go @@ -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}, diff --git a/api/server/special_handler_test.go b/api/server/special_handler_test.go index b494a904c..c424b4b43 100644 --- a/api/server/special_handler_test.go +++ b/api/server/special_handler_test.go @@ -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{}, diff --git a/docs/definitions.md b/docs/definitions.md index cc94419b8..e2be0bb5b 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -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: @@ -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": { diff --git a/docs/function-file.md b/docs/function-file.md index 93f0aca7d..6ae65cc31 100644 --- a/docs/function-file.md +++ b/docs/function-file.md @@ -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 diff --git a/docs/operating/docker-swarm/README.md b/docs/operating/docker-swarm/README.md index f395b79ac..706fcb67e 100644 --- a/docs/operating/docker-swarm/README.md +++ b/docs/operating/docker-swarm/README.md @@ -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! @@ -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! diff --git a/docs/operating/kubernetes/README.md b/docs/operating/kubernetes/README.md index 20965aab4..8e082e831 100644 --- a/docs/operating/kubernetes/README.md +++ b/docs/operating/kubernetes/README.md @@ -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! @@ -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! diff --git a/docs/operating/routes.md b/docs/operating/routes.md index 37be4f6cb..d09c86dae 100644 --- a/docs/operating/routes.md +++ b/docs/operating/routes.md @@ -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"} diff --git a/docs/usage.md b/docs/usage.md index 8adf034ab..bd5f2baaf 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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: @@ -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 ``` @@ -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 ``` diff --git a/examples/blog/README.md b/examples/blog/README.md index 7ed61114c..50c3afb00 100644 --- a/examples/blog/README.md +++ b/examples/blog/README.md @@ -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 . ``` diff --git a/fn/README.md b/fn/README.md index a520b4a39..bfe3fc7a4 100644 --- a/fn/README.md +++ b/fn/README.md @@ -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 @@ -111,7 +111,7 @@ 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` @@ -119,7 +119,7 @@ You can also update existent routes configurations using the command `fn routes 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 @@ -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 ``` @@ -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 @@ -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 diff --git a/lb/lb_test.go b/lb/lb_test.go index 1b6462061..9b3feef0f 100644 --- a/lb/lb_test.go +++ b/lb/lb_test.go @@ -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 } }