response_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package middleware
  2. import (
  3. "testing"
  4. "fmt"
  5. "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/admin/main/aegis/model"
  7. "go-common/app/admin/main/aegis/model/resource"
  8. )
  9. func TestMiddlewareRequest(t *testing.T) {
  10. convey.Convey("Request", t, func(ctx convey.C) {
  11. opt := new(model.SearchParams)
  12. opt2 := &model.SearchParams{
  13. Extra1: "2",
  14. }
  15. ds.Encode = false
  16. Request(opt, &ds)
  17. Request(opt2, &ds)
  18. ctx.Convey("No return values", func(ctx convey.C) {
  19. ctx.So(opt.Extra1, convey.ShouldEqual, "")
  20. ctx.So(opt2.Extra1, convey.ShouldEqual, ds.Cfg[0].Hitv)
  21. })
  22. })
  23. }
  24. func TestMiddlewareResponse(t *testing.T) {
  25. convey.Convey("Response", t, func(ctx convey.C) {
  26. opt := new(model.AuditInfo)
  27. opt2 := &model.AuditInfo{
  28. Resource: &resource.Res{Extra1: 4},
  29. }
  30. ds.Encode = true
  31. Response(opt, nil, nil, &ds)
  32. Response(opt2, nil, nil, &ds)
  33. ctx.Convey("No return values", func(ctx convey.C) {
  34. ctx.So(opt.Resource, convey.ShouldBeNil)
  35. ctx.So(fmt.Sprintf("%v", opt2.Resource.Extra1), convey.ShouldEqual, ds.Cfg[0].Mapv)
  36. })
  37. })
  38. }