btrfsutils_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package btrfsutils
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. const (
  20. lines = `ID 256 gen 32 top level 5 path @
  21. ID 257 gen 872 top level 256 path @/var
  22. ID 258 gen 869 top level 256 path @/usr/local
  23. ID 259 gen 872 top level 256 path @/tmp
  24. ID 260 gen 35 top level 256 path @/srv
  25. ID 261 gen 872 top level 256 path @/root
  26. ID 262 gen 871 top level 256 path @/opt
  27. ID 263 gen 35 top level 256 path @/home
  28. ID 264 gen 26 top level 256 path @/boot/grub2/x86_64-efi
  29. ID 265 gen 64 top level 256 path @/boot/grub2/i386-pc
  30. ID 266 gen 66 top level 256 path @/.snapshots
  31. ID 267 gen 873 top level 266 path @/.snapshots/1/snapshot
  32. ID 272 gen 65 top level 266 path @/.snapshots/2/snapshot
  33. `
  34. )
  35. func TestParseBtrfsSubvols(t *testing.T) {
  36. subvols := parseBtrfsSubvols(lines)
  37. want := []string{"@/var", "@/usr/local", "@/tmp", "@/srv", "@/root", "@/opt", "@/home",
  38. "@/boot/grub2/x86_64-efi", "@/boot/grub2/i386-pc", "@/.snapshots",
  39. "@/.snapshots/1/snapshot", "@/.snapshots/2/snapshot",
  40. }
  41. if !reflect.DeepEqual(subvols, want) {
  42. t.Errorf("expect %s got %s", want, subvols)
  43. }
  44. }