You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2KB

  1. package main
  2. import (
  3. "testing"
  4. "github.com/kataras/iris/v12"
  5. "github.com/kataras/iris/v12/httptest"
  6. "github.com/kataras/iris/v12/versioning"
  7. )
  8. func TestVersionedController(t *testing.T) {
  9. app := newApp()
  10. e := httptest.New(t, app)
  11. e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "1.0.0").Expect().
  12. Status(iris.StatusOK).Body().Equal("data (v1.x)")
  13. e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "2.3.0").Expect().
  14. Status(iris.StatusOK).Body().Equal("data (v2.x)")
  15. e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "3.1.0").Expect().
  16. Status(iris.StatusOK).Body().Equal("data (v3.x)")
  17. // Test invalid version or no version at all.
  18. e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "4.0.0").Expect().
  19. Status(iris.StatusOK).Body().Equal("data")
  20. e.GET("/data").Expect().
  21. Status(iris.StatusOK).Body().Equal("data")
  22. // Test Deprecated (v1)
  23. ex := e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "1.0.0").Expect()
  24. ex.Status(iris.StatusOK).Body().Equal("data (v1.x)")
  25. ex.Header("X-API-Warn").Equal(opts.WarnMessage)
  26. expectedDateStr := opts.DeprecationDate.Format(app.ConfigurationReadOnly().GetTimeFormat())
  27. ex.Header("X-API-Deprecation-Date").Equal(expectedDateStr)
  28. }