mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Improving API tests
This commit is contained in:
committed by
James Jeffrey
parent
e0569192ee
commit
5b41fe2dc7
@@ -1,41 +1,63 @@
|
||||
package tests
|
||||
|
||||
//
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/funcy/functions_go/models"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/id"
|
||||
)
|
||||
|
||||
func TestRoutes(t *testing.T) {
|
||||
s := SetupDefaultSuite()
|
||||
|
||||
newRouteType := "sync"
|
||||
newRoutePath := "/new-hello"
|
||||
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
newRoutePath := id.New().String()
|
||||
|
||||
t.Run("create-route", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
CreateRoute(t, s.Context, s.Client, s.AppName, s.RoutePath, s.Image, s.RouteType,
|
||||
s.RouteConfig, s.RouteHeaders)
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
t.Run("list-and-find-route", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
CreateRoute(t, s.Context, s.Client, s.AppName, s.RoutePath, s.Image, s.RouteType,
|
||||
s.RouteConfig, s.RouteHeaders)
|
||||
if !assertContainsRoute(ListRoutes(t, s.Context, s.Client, s.AppName), s.RoutePath) {
|
||||
t.Fatalf("Unable to find corresponding route `%v` in list", s.RoutePath)
|
||||
t.Errorf("Unable to find corresponding route `%v` in list", s.RoutePath)
|
||||
}
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
t.Run("can-get-corresponding-route", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
CreateRoute(t, s.Context, s.Client, s.AppName, s.RoutePath, s.Image, s.RouteType,
|
||||
s.RouteConfig, s.RouteHeaders)
|
||||
|
||||
rObjects := []*models.Route{GetRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)}
|
||||
if !assertContainsRoute(rObjects, s.RoutePath) {
|
||||
t.Fatalf("Unable to find corresponding route `%v` in list", s.RoutePath)
|
||||
t.Errorf("Unable to find corresponding route `%v` in list", s.RoutePath)
|
||||
}
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
t.Run("can-update-route-info", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
CreateRoute(t, s.Context, s.Client, s.AppName, s.RoutePath, s.Image, s.RouteType,
|
||||
s.RouteConfig, s.RouteHeaders)
|
||||
|
||||
routeResp, err := UpdateRoute(
|
||||
t, s.Context, s.Client,
|
||||
s.AppName, s.RoutePath,
|
||||
@@ -45,39 +67,66 @@ func TestRoutes(t *testing.T) {
|
||||
CheckRouteResponseError(t, err)
|
||||
assertRouteFields(t, routeResp.Payload.Route, s.RoutePath, s.Image, newRouteType)
|
||||
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
t.Run("fail-to-update-route-path", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
CreateRoute(t, s.Context, s.Client, s.AppName, s.RoutePath, s.Image, s.RouteType,
|
||||
s.RouteConfig, s.RouteHeaders)
|
||||
|
||||
_, err := UpdateRoute(
|
||||
t, s.Context, s.Client,
|
||||
s.AppName, s.RoutePath,
|
||||
s.Image, s.RouteType, s.Format,
|
||||
s.Memory, s.RouteConfig, s.RouteHeaders, newRoutePath)
|
||||
if err == nil {
|
||||
t.Fatalf("Route path suppose to be immutable, but it's not.")
|
||||
t.Errorf("Route path suppose to be immutable, but it's not.")
|
||||
}
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
t.Run("create-route-duplicate", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
CreateRoute(t, s.Context, s.Client, s.AppName, s.RoutePath, s.Image, s.RouteType,
|
||||
s.RouteConfig, s.RouteHeaders)
|
||||
|
||||
_, err := createRoute(s.Context, s.Client, s.AppName, s.Image, s.RoutePath, newRouteType, s.RouteConfig, s.RouteHeaders)
|
||||
if err == nil {
|
||||
t.Fatalf("Route duplicate error should appear, but it didn't")
|
||||
t.Errorf("Route duplicate error should appear, but it didn't")
|
||||
}
|
||||
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
t.Run("can-delete-route", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
CreateRoute(t, s.Context, s.Client, s.AppName, s.RoutePath, s.Image, s.RouteType,
|
||||
s.RouteConfig, s.RouteHeaders)
|
||||
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
t.Run("fail-to-delete-missing-route", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
|
||||
|
||||
_, err := deleteRoute(s.Context, s.Client, s.AppName, "dummy-route")
|
||||
if err == nil {
|
||||
t.Fatal("Delete from missing route must fail.")
|
||||
t.Error("Delete from missing route must fail.")
|
||||
}
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
})
|
||||
|
||||
DeleteApp(t, s.Context, s.Client, s.AppName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user