graphmanager_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. var DBDIRS = []string{GraphManagerTestDBDir1, GraphManagerTestDBDir2,
  29. GraphManagerTestDBDir3, GraphManagerTestDBDir4}
  30. const InvlaidFileName = "**" + string(0x0)
  31. // Main function for all tests in this package
  32. func TestMain(m *testing.M) {
  33. flag.Parse()
  34. for _, dbdir := range DBDIRS {
  35. if res, _ := fileutil.PathExists(dbdir); res {
  36. if err := os.RemoveAll(dbdir); err != nil {
  37. fmt.Print("Could not remove test directory:", err.Error())
  38. }
  39. }
  40. }
  41. // Run the tests
  42. res := m.Run()
  43. // Teardown
  44. for _, dbdir := range DBDIRS {
  45. if res, _ := fileutil.PathExists(dbdir); res {
  46. if err := os.RemoveAll(dbdir); err != nil {
  47. fmt.Print("Could not remove test directory:", err.Error())
  48. }
  49. }
  50. }
  51. os.Exit(res)
  52. }
  53. /*
  54. NewGraphManager returns a new GraphManager instance without loading rules.
  55. */
  56. func newGraphManagerNoRules(gs graphstorage.Storage) *Manager {
  57. return createGraphManager(gs)
  58. }