index_meta_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2014 Couchbase, Inc.
  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 bleve
  15. import (
  16. "os"
  17. "testing"
  18. )
  19. func TestIndexMeta(t *testing.T) {
  20. var testIndexPath = "doesnotexit.bleve"
  21. defer func() {
  22. err := os.RemoveAll(testIndexPath)
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. }()
  27. // open non-existent meta should give an error
  28. _, err := openIndexMeta(testIndexPath)
  29. if err == nil {
  30. t.Errorf("expected error, got nil")
  31. }
  32. // create meta
  33. im := &indexMeta{Storage: "boltdb"}
  34. err = im.Save(testIndexPath)
  35. if err != nil {
  36. t.Error(err)
  37. }
  38. im = nil
  39. // open a meta that exists
  40. im, err = openIndexMeta(testIndexPath)
  41. if err != nil {
  42. t.Error(err)
  43. }
  44. if im.Storage != "boltdb" {
  45. t.Errorf("expected storage 'boltdb', got '%s'", im.Storage)
  46. }
  47. // save a meta that already exists
  48. err = im.Save(testIndexPath)
  49. if err == nil {
  50. t.Errorf("expected error, got nil")
  51. }
  52. }