2018-11-10 02:49:32 +01:00
|
|
|
package versioning_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
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 TestDeprecated(t *testing.T) {
|
|
|
|
app := iris.New()
|
|
|
|
|
|
|
|
writeVesion := func(ctx iris.Context) {
|
|
|
|
ctx.WriteString(versioning.GetVersion(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
opts := versioning.DeprecationOptions{
|
|
|
|
WarnMessage: "deprecated, see <this link>",
|
|
|
|
DeprecationDate: time.Now().UTC(),
|
|
|
|
DeprecationInfo: "a bigger version is available, see <this link> for more information",
|
|
|
|
}
|
|
|
|
app.Get("/", versioning.Deprecated(writeVesion, opts))
|
|
|
|
|
|
|
|
e := httptest.New(t, app)
|
|
|
|
|
|
|
|
ex := e.GET("/").WithHeader(versioning.AcceptVersionHeaderKey, "1.0").Expect()
|
2023-07-08 01:08:18 +02:00
|
|
|
ex.Status(iris.StatusOK).Body().IsEqual("1.0")
|
2018-11-10 02:49:32 +01:00
|
|
|
ex.Header("X-API-Warn").Equal(opts.WarnMessage)
|
|
|
|
expectedDateStr := opts.DeprecationDate.Format(app.ConfigurationReadOnly().GetTimeFormat())
|
|
|
|
ex.Header("X-API-Deprecation-Date").Equal(expectedDateStr)
|
|
|
|
}
|