ldp_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package gold
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestLinkHeaderParser(t *testing.T) {
  7. l := ParseLinkHeader("")
  8. assert.Equal(t, "", l.MatchRel("acl"))
  9. l = ParseLinkHeader("<http://www.w3.org/ns/ldp#Container>; rel='type'")
  10. assert.NotEmpty(t, l.headers)
  11. assert.True(t, l.MatchURI("http://www.w3.org/ns/ldp#Container"))
  12. assert.False(t, l.MatchURI("http://www.w3.org/ns/ldp#Resource"))
  13. assert.Equal(t, "http://www.w3.org/ns/ldp#Container", l.MatchRel("type"))
  14. l = ParseLinkHeader("<http://www.w3.org/ns/ldp#Container>; rel=\"type\", <http://www.w3.org/ns/ldp#Resource>; rel=\"type\"")
  15. assert.NotEmpty(t, l.headers)
  16. assert.True(t, l.MatchURI("http://www.w3.org/ns/ldp#Container"))
  17. assert.True(t, l.MatchURI("http://www.w3.org/ns/ldp#Resource"))
  18. }
  19. func TestPreferHeaderParser(t *testing.T) {
  20. l := ParsePreferHeader("return=representation; omit=\"http://www.w3.org/ns/ldp#PreferMembership http://www.w3.org/ns/ldp#PreferContainment\"")
  21. assert.NotEmpty(t, l.headers)
  22. assert.Equal(t, 2, len(l.Omits()))
  23. for i, uri := range l.Omits() {
  24. if i == 0 {
  25. assert.Equal(t, "http://www.w3.org/ns/ldp#PreferMembership", uri)
  26. } else {
  27. assert.Equal(t, "http://www.w3.org/ns/ldp#PreferContainment", uri)
  28. }
  29. }
  30. l = ParsePreferHeader("return=representation; include=\"http://www.w3.org/ns/ldp#PreferMembership http://www.w3.org/ns/ldp#PreferContainment\"")
  31. assert.NotEmpty(t, l.headers)
  32. assert.Equal(t, 2, len(l.Includes()))
  33. for i, uri := range l.Includes() {
  34. if i == 0 {
  35. assert.Equal(t, "http://www.w3.org/ns/ldp#PreferMembership", uri)
  36. } else {
  37. assert.Equal(t, "http://www.w3.org/ns/ldp#PreferContainment", uri)
  38. }
  39. }
  40. }
  41. func TestNewUUID(t *testing.T) {
  42. uuid := NewUUID()
  43. assert.Equal(t, 32, len(uuid))
  44. }