leveldb_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package files
  16. import (
  17. "bytes"
  18. "testing"
  19. )
  20. func TestDeviceKey(t *testing.T) {
  21. fld := []byte("folder6789012345678901234567890123456789012345678901234567890123")
  22. dev := []byte("device67890123456789012345678901")
  23. name := []byte("name")
  24. key := deviceKey(fld, dev, name)
  25. fld2 := deviceKeyFolder(key)
  26. if bytes.Compare(fld2, fld) != 0 {
  27. t.Errorf("wrong folder %q != %q", fld2, fld)
  28. }
  29. dev2 := deviceKeyDevice(key)
  30. if bytes.Compare(dev2, dev) != 0 {
  31. t.Errorf("wrong device %q != %q", dev2, dev)
  32. }
  33. name2 := deviceKeyName(key)
  34. if bytes.Compare(name2, name) != 0 {
  35. t.Errorf("wrong name %q != %q", name2, name)
  36. }
  37. }
  38. func TestGlobalKey(t *testing.T) {
  39. fld := []byte("folder6789012345678901234567890123456789012345678901234567890123")
  40. name := []byte("name")
  41. key := globalKey(fld, name)
  42. fld2 := globalKeyFolder(key)
  43. if bytes.Compare(fld2, fld) != 0 {
  44. t.Errorf("wrong folder %q != %q", fld2, fld)
  45. }
  46. name2 := globalKeyName(key)
  47. if bytes.Compare(name2, name) != 0 {
  48. t.Errorf("wrong name %q != %q", name2, name)
  49. }
  50. }