conf_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // conf_test.go - Tests for conf.go.
  2. //
  3. // Copyright (c) 2013 The go-alpm Authors
  4. //
  5. // MIT Licensed. See LICENSE for details.
  6. package alpm
  7. import (
  8. "os"
  9. "reflect"
  10. "testing"
  11. )
  12. var pacmanConfRef = PacmanConfig{
  13. RootDir: "/",
  14. DBPath: "/var/lib/pacman",
  15. CacheDir: []string{"/var/cache/pacman/pkg", "/other/cachedir"},
  16. LogFile: "/var/log/pacman.log",
  17. GPGDir: "/etc/pacman.d/gnupg/",
  18. HoldPkg: []string{"pacman", "glibc"},
  19. XferCommand: "/usr/bin/wget --passive-ftp -c -O %o %u",
  20. Architecture: "auto",
  21. CleanMethod: "KeepInstalled",
  22. UseDelta: 0.7,
  23. IgnorePkg: []string{"hello", "world"},
  24. IgnoreGroup: []string{"kde"},
  25. NoUpgrade: nil,
  26. NoExtract: nil,
  27. Options: ConfColor | ConfCheckSpace | ConfVerbosePkgLists,
  28. Repos: []RepoConfig{
  29. {Name: "core", Servers: []string{"ftp://ftp.example.com/foobar/$repo/os/$arch/"}},
  30. {Name: "custom", Servers: []string{"file:///home/custompkgs"}},
  31. },
  32. }
  33. func detailedDeepEqual(t *testing.T, x, y interface{}) {
  34. v := reflect.ValueOf(x)
  35. w := reflect.ValueOf(y)
  36. if v.Type() != w.Type() {
  37. t.Errorf("differing types %T vs. %T", x, y)
  38. return
  39. }
  40. for i := 0; i < v.NumField(); i++ {
  41. v_fld := v.Field(i).Interface()
  42. w_fld := w.Field(i).Interface()
  43. if !reflect.DeepEqual(v_fld, w_fld) {
  44. t.Errorf("field %s differs: got %#v, expected %#v",
  45. v.Type().Field(i).Name, v_fld, w_fld)
  46. }
  47. }
  48. }
  49. func TestParseConfigGood(t *testing.T) {
  50. f, err := os.Open("testing/conf/good_pacman.conf")
  51. if err != nil {
  52. t.Error(err)
  53. }
  54. conf, err := ParseConfig(f)
  55. if err != nil {
  56. t.Error(err)
  57. }
  58. detailedDeepEqual(t, conf, pacmanConfRef)
  59. }