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.

55 lines
1.4 KiB

  1. package needle
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/storage/types"
  4. "testing"
  5. )
  6. func TestParseFileIdFromString(t *testing.T) {
  7. fidStr1 := "100,12345678"
  8. _, err := ParseFileIdFromString(fidStr1)
  9. if err == nil {
  10. t.Errorf("%s : KeyHash is too short", fidStr1)
  11. }
  12. fidStr1 = "100, 12345678"
  13. _, err = ParseFileIdFromString(fidStr1)
  14. if err == nil {
  15. t.Errorf("%s : needlId invalid syntax", fidStr1)
  16. }
  17. fidStr1 = "100,123456789"
  18. _, err = ParseFileIdFromString(fidStr1)
  19. if err != nil {
  20. t.Errorf("%s : should be OK", fidStr1)
  21. }
  22. var fileId *FileId
  23. fidStr1 = "100,123456789012345678901234"
  24. fileId, err = ParseFileIdFromString(fidStr1)
  25. if err != nil {
  26. t.Errorf("%s : should be OK", fidStr1)
  27. }
  28. if !(fileId.VolumeId == VolumeId(100) &&
  29. fileId.Key == types.NeedleId(0x1234567890123456) &&
  30. fileId.Cookie == types.Cookie(types.Uint32ToCookie(uint32(0x78901234)))) {
  31. t.Errorf("src : %s, dest : %v", fidStr1, fileId)
  32. }
  33. fidStr1 = "100,abcd0000abcd"
  34. fileId, err = ParseFileIdFromString(fidStr1)
  35. if err != nil {
  36. t.Errorf("%s : should be OK", fidStr1)
  37. }
  38. if !(fileId.VolumeId == VolumeId(100) &&
  39. fileId.Key == types.NeedleId(0xabcd) &&
  40. fileId.Cookie == types.Cookie(types.Uint32ToCookie(uint32(0xabcd)))) {
  41. t.Errorf("src : %s, dest : %v", fidStr1, fileId)
  42. }
  43. fidStr1 = "100,1234567890123456789012345"
  44. _, err = ParseFileIdFromString(fidStr1)
  45. if err == nil {
  46. t.Errorf("%s : needleId is too long", fidStr1)
  47. }
  48. }