pathinfo_test.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package gold
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestPathInfoWithoutTrailingSlash(t *testing.T) {
  7. sroot := serverDefaultRoot()
  8. req := &httpRequest{nil, handler, "", "", "", false}
  9. p, err := req.pathInfo(testServer.URL)
  10. assert.Nil(t, err)
  11. assert.Equal(t, testServer.URL+"/", p.URI)
  12. assert.Equal(t, testServer.URL, p.Base)
  13. assert.Equal(t, "", p.Path)
  14. assert.Equal(t, sroot, p.File)
  15. assert.Equal(t, testServer.URL+"/"+config.ACLSuffix, p.AclURI)
  16. assert.Equal(t, sroot+config.ACLSuffix, p.AclFile)
  17. assert.Equal(t, testServer.URL+"/"+config.MetaSuffix, p.MetaURI)
  18. assert.Equal(t, sroot+config.MetaSuffix, p.MetaFile)
  19. assert.Empty(t, p.Extension)
  20. assert.True(t, p.Exists)
  21. }
  22. func TestPathInfoWithTrailingSlash(t *testing.T) {
  23. sroot := serverDefaultRoot()
  24. req := &httpRequest{nil, handler, "", "", "", false}
  25. p, err := req.pathInfo(testServer.URL + "/")
  26. assert.Nil(t, err)
  27. assert.Equal(t, testServer.URL, p.Base)
  28. assert.Equal(t, testServer.URL+"/", p.URI)
  29. assert.Equal(t, "", p.Path)
  30. assert.Equal(t, sroot, p.File)
  31. assert.Equal(t, testServer.URL+"/"+config.ACLSuffix, p.AclURI)
  32. assert.Equal(t, sroot+config.ACLSuffix, p.AclFile)
  33. assert.Equal(t, testServer.URL+"/"+config.MetaSuffix, p.MetaURI)
  34. assert.Equal(t, sroot+config.MetaSuffix, p.MetaFile)
  35. assert.Empty(t, p.Extension)
  36. assert.True(t, p.Exists)
  37. }
  38. func TestPathInfoWithPath(t *testing.T) {
  39. path := testServer.URL + "/_test/"
  40. sroot := serverDefaultRoot()
  41. req := &httpRequest{nil, handler, "", "", "", false}
  42. p, err := req.pathInfo(path)
  43. assert.Nil(t, err)
  44. assert.Equal(t, path, p.URI)
  45. assert.Equal(t, testServer.URL, p.Base)
  46. assert.Equal(t, "_test/", p.Path)
  47. assert.Equal(t, sroot+"_test/", p.File)
  48. assert.Equal(t, path+config.ACLSuffix, p.AclURI)
  49. assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.AclFile)
  50. assert.Equal(t, path+config.MetaSuffix, p.MetaURI)
  51. assert.Equal(t, sroot+"_test/"+config.MetaSuffix, p.MetaFile)
  52. assert.Empty(t, p.Extension)
  53. assert.True(t, p.Exists)
  54. }
  55. func TestPathInfoWithPathAndChildDir(t *testing.T) {
  56. path := testServer.URL + "/_test/"
  57. sroot := serverDefaultRoot()
  58. req := &httpRequest{nil, handler, "", "", "", false}
  59. p, err := req.pathInfo(path + "dir/")
  60. assert.Nil(t, err)
  61. assert.Equal(t, path+"dir/", p.URI)
  62. assert.Equal(t, testServer.URL, p.Base)
  63. assert.Equal(t, "_test/dir/", p.Path)
  64. assert.Equal(t, path, p.ParentURI)
  65. assert.Equal(t, sroot+"_test/dir/", p.File)
  66. assert.Equal(t, path+"dir/"+config.ACLSuffix, p.AclURI)
  67. assert.Equal(t, sroot+"_test/dir/"+config.ACLSuffix, p.AclFile)
  68. assert.Equal(t, path+"dir/"+config.MetaSuffix, p.MetaURI)
  69. assert.Equal(t, sroot+"_test/dir/"+config.MetaSuffix, p.MetaFile)
  70. assert.Empty(t, p.Extension)
  71. assert.False(t, p.Exists)
  72. }
  73. func TestPathInfoWithPathAndChildFile(t *testing.T) {
  74. path := testServer.URL + "/_test/"
  75. sroot := serverDefaultRoot()
  76. req := &httpRequest{nil, handler, "", "", "", false}
  77. p, err := req.pathInfo(path + "abc")
  78. assert.Nil(t, err)
  79. assert.Equal(t, path+"abc", p.URI)
  80. assert.Equal(t, testServer.URL, p.Base)
  81. assert.Equal(t, "_test/abc", p.Path)
  82. assert.Equal(t, path, p.ParentURI)
  83. assert.Equal(t, sroot+"_test/abc", p.File)
  84. assert.Equal(t, path+"abc"+config.ACLSuffix, p.AclURI)
  85. assert.Equal(t, sroot+"_test/abc"+config.ACLSuffix, p.AclFile)
  86. assert.Equal(t, path+"abc"+config.MetaSuffix, p.MetaURI)
  87. assert.Equal(t, sroot+"_test/abc"+config.MetaSuffix, p.MetaFile)
  88. assert.Empty(t, p.Extension)
  89. assert.False(t, p.Exists)
  90. }
  91. func TestPathInfoWithPathAndACLSuffix(t *testing.T) {
  92. path := testServer.URL + "/_test/"
  93. sroot := serverDefaultRoot()
  94. req := &httpRequest{nil, handler, "", "", "", false}
  95. p, err := req.pathInfo(path + config.ACLSuffix)
  96. assert.Nil(t, err)
  97. assert.Equal(t, path+config.ACLSuffix, p.URI)
  98. assert.Equal(t, testServer.URL, p.Base)
  99. assert.Equal(t, "_test/"+config.ACLSuffix, p.Path)
  100. assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.File)
  101. assert.Equal(t, path+config.ACLSuffix, p.AclURI)
  102. assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.AclFile)
  103. assert.Equal(t, path+config.ACLSuffix, p.MetaURI)
  104. assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.MetaFile)
  105. assert.Equal(t, config.ACLSuffix, p.Extension)
  106. assert.False(t, p.Exists)
  107. }
  108. func TestPathInfoWithPathAndMetaSuffix(t *testing.T) {
  109. path := testServer.URL + "/_test/"
  110. sroot := serverDefaultRoot()
  111. req := &httpRequest{nil, handler, "", "", "", false}
  112. p, err := req.pathInfo(path + config.MetaSuffix)
  113. assert.Nil(t, err)
  114. assert.Equal(t, path+config.MetaSuffix, p.URI)
  115. assert.Equal(t, testServer.URL, p.Base)
  116. assert.Equal(t, "_test/"+config.MetaSuffix, p.Path)
  117. assert.Equal(t, sroot+"_test/"+config.MetaSuffix, p.File)
  118. assert.Equal(t, path+config.MetaSuffix+config.ACLSuffix, p.AclURI)
  119. assert.Equal(t, sroot+"_test/"+config.MetaSuffix+config.ACLSuffix, p.AclFile)
  120. assert.Equal(t, path+config.MetaSuffix, p.MetaURI)
  121. assert.Equal(t, sroot+"_test/"+config.MetaSuffix, p.MetaFile)
  122. assert.Equal(t, config.MetaSuffix, p.Extension)
  123. assert.False(t, p.Exists)
  124. }