2018-11-10 02:49:32 +01:00
|
|
|
package versioning_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/httptest"
|
|
|
|
"github.com/kataras/iris/v12/versioning"
|
2018-11-10 02:49:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetVersion(t *testing.T) {
|
|
|
|
app := iris.New()
|
|
|
|
|
|
|
|
writeVesion := func(ctx iris.Context) {
|
|
|
|
ctx.WriteString(versioning.GetVersion(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Get("/", writeVesion)
|
|
|
|
app.Get("/manual", func(ctx iris.Context) {
|
2020-05-06 06:17:24 +02:00
|
|
|
ctx.SetVersion("11.0.5")
|
2018-11-10 02:49:32 +01:00
|
|
|
ctx.Next()
|
|
|
|
}, writeVesion)
|
|
|
|
|
|
|
|
e := httptest.New(t, app)
|
|
|
|
|
|
|
|
e.GET("/").WithHeader(versioning.AcceptVersionHeaderKey, "1.0").Expect().
|
|
|
|
Status(iris.StatusOK).Body().Equal("1.0")
|
|
|
|
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version=2.1").Expect().
|
|
|
|
Status(iris.StatusOK).Body().Equal("2.1")
|
|
|
|
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version=2.1 ;other=dsa").Expect().
|
|
|
|
Status(iris.StatusOK).Body().Equal("2.1")
|
|
|
|
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "version=2.1").Expect().
|
|
|
|
Status(iris.StatusOK).Body().Equal("2.1")
|
|
|
|
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "version=1").Expect().
|
|
|
|
Status(iris.StatusOK).Body().Equal("1")
|
|
|
|
|
|
|
|
// unknown versions.
|
|
|
|
e.GET("/").WithHeader(versioning.AcceptVersionHeaderKey, "").Expect().
|
2020-05-06 06:17:24 +02:00
|
|
|
Status(iris.StatusOK).Body().Equal("")
|
2018-11-10 02:49:32 +01:00
|
|
|
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version=").Expect().
|
2020-05-06 06:17:24 +02:00
|
|
|
Status(iris.StatusOK).Body().Equal("")
|
2018-11-10 02:49:32 +01:00
|
|
|
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version= ;other=dsa").Expect().
|
2020-05-06 06:17:24 +02:00
|
|
|
Status(iris.StatusOK).Body().Equal("")
|
2018-11-10 02:49:32 +01:00
|
|
|
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "version=").Expect().
|
2020-05-06 06:17:24 +02:00
|
|
|
Status(iris.StatusOK).Body().Equal("")
|
2018-11-10 02:49:32 +01:00
|
|
|
|
|
|
|
e.GET("/manual").Expect().Status(iris.StatusOK).Body().Equal("11.0.5")
|
|
|
|
}
|