mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Address broken tests
This commit is contained in:
committed by
James Jeffrey
parent
04008c71fd
commit
31b4ac4516
@@ -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",
|
||||
}
|
||||
|
||||
@@ -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 */ }
|
||||
|
||||
@@ -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"},
|
||||
}
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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{},
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -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 .
|
||||
```
|
||||
|
||||
|
||||
16
fn/README.md
16
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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user