graphmanager_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package graph
  11. import (
  12. "flag"
  13. "fmt"
  14. "os"
  15. "testing"
  16. "devt.de/krotik/common/fileutil"
  17. "devt.de/krotik/eliasdb/graph/graphstorage"
  18. )
  19. /*
  20. Flag to enable / disable tests which use actual disk storage.
  21. (Only used for test development - should never be false)
  22. */
  23. const RunDiskStorageTests = true
  24. const GraphManagerTestDBDir1 = "gmtest1"
  25. const GraphManagerTestDBDir2 = "gmtest2"
  26. const GraphManagerTestDBDir3 = "gmtest3"
  27. const GraphManagerTestDBDir4 = "gmtest4"
  28. const GraphManagerTestDBDir5 = "gmtest5"
  29. const GraphManagerTestDBDir6 = "gmtest6"
  30. var DBDIRS = []string{GraphManagerTestDBDir1, GraphManagerTestDBDir2,
  31. GraphManagerTestDBDir3, GraphManagerTestDBDir4, GraphManagerTestDBDir5,
  32. GraphManagerTestDBDir6}
  33. const InvlaidFileName = "**" + string(0x0)
  34. // Main function for all tests in this package
  35. func TestMain(m *testing.M) {
  36. flag.Parse()
  37. for _, dbdir := range DBDIRS {
  38. if res, _ := fileutil.PathExists(dbdir); res {
  39. if err := os.RemoveAll(dbdir); err != nil {
  40. fmt.Print("Could not remove test directory:", err.Error())
  41. }
  42. }
  43. }
  44. // Run the tests
  45. res := m.Run()
  46. // Teardown
  47. for _, dbdir := range DBDIRS {
  48. if res, _ := fileutil.PathExists(dbdir); res {
  49. if err := os.RemoveAll(dbdir); err != nil {
  50. fmt.Print("Could not remove test directory:", err.Error())
  51. }
  52. }
  53. }
  54. os.Exit(res)
  55. }
  56. /*
  57. NewGraphManager returns a new GraphManager instance without loading rules.
  58. */
  59. func newGraphManagerNoRules(gs graphstorage.Storage) *Manager {
  60. return createGraphManager(gs)
  61. }