Skip to content

Commit

Permalink
Manager.Start() ignores empty server for testability
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyen committed Oct 17, 2014
1 parent fe6044b commit 51797b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ import (
func TestMainStart(t *testing.T) {
router, err := mainStart("./data", "./static", "")
if router != nil || err == nil {
t.Errorf("expected empty server string to fail")
t.Errorf("expected empty server string to fail mainStart()")
}
}
19 changes: 11 additions & 8 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,20 @@ func (mgr *Manager) ParsePIndexPath(pindexPath string) (string, bool) {
}

func (mgr *Manager) Start() error {
// First, check if couchbase server is invalid to exit early.
// Afterwards, any later loss of couchbase conns, in contrast,
// won't exit the server, where cbft will instead retry/reconnect.

// TODO: if we handle multiple "seed" servers, what if those
// seeds actually come from different clusters? Can we have
// multiple clusters fan-in to a single cbft?
_, err := couchbase.Connect(mgr.server)
if err != nil {
return fmt.Errorf("error: could not connect to couchbase server URL: %s, err: %v",
mgr.server, err)
//
// First, check if couchbase server is invalid to exit early.
// Afterwards, any later loss of couchbase conns, in contrast,
// won't exit the server, where cbft will instead retry/reconnect.
// Empty server ("") allows for unit testing.
if mgr.server != "" {
_, err := couchbase.Connect(mgr.server)
if err != nil {
return fmt.Errorf("error: could not connect to couchbase server URL: %s, err: %v",
mgr.server, err)
}
}

// walk the data dir and register pindexes
Expand Down
12 changes: 12 additions & 0 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package main

import (
"io/ioutil"
"os"
"testing"
)
Expand All @@ -34,4 +35,15 @@ func TestManagerStart(t *testing.T) {
if m.Start() == nil {
t.Errorf("expected NewManager() with bad svr should fail")
}

m = NewManager("not-a-real-dir", "", nil)
if m.Start() == nil {
t.Errorf("expected NewManager() with bad dir should fail")
}
emptyDir, _ := ioutil.TempDir("./tmp", "test")
defer os.RemoveAll(emptyDir)
m = NewManager(emptyDir, "", nil)
if err := m.Start(); err != nil {
t.Errorf("expected NewManager() with empty dir to work, err: %v", err)
}
}
4 changes: 4 additions & 0 deletions tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

0 comments on commit 51797b9

Please sign in to comment.