Skip to content

Commit

Permalink
Add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Rozlach committed Aug 31, 2016
1 parent 3449f0a commit 5ccb459
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
22 changes: 22 additions & 0 deletions zk/server_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,25 @@ func (tc *TestCluster) StopServer(server string) {
}
panic(fmt.Sprintf("Unknown server: %s", server))
}

func (tc *TestCluster) StartAllServers() error {
for _, s := range tc.Servers {
if err := s.Srv.Start(); err != nil {
return fmt.Errorf(
"Failed to start server listening on port `%d` : %+v", s.Port, err)
}
}

return nil
}

func (tc *TestCluster) StopAllServers() error {
for _, s := range tc.Servers {
if err := s.Srv.Stop(); err != nil {
return fmt.Errorf(
"Failed to stop server listening on port `%d` : %+v", s.Port, err)
}
}

return nil
}
51 changes: 51 additions & 0 deletions zk/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,57 @@ func TestMulti(t *testing.T) {
}
}

func TestIfAuthdataSurvivesReconnect(t *testing.T) {
// This test case ensures authentication data is being resubmited after
// reconnect.
testNode := "/auth-testnode"

ts, err := StartTestCluster(1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
}

zk, _, err := ts.ConnectAll()
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
defer zk.Close()

acl := DigestACL(PermAll, "userfoo", "passbar")

_, err = zk.Create(testNode, []byte("Some very secret content"), 0, acl)
if err != nil && err != ErrNodeExists {
t.Fatalf("Failed to create test node : %+v", err)
}

_, _, err = zk.Get(testNode)
if err == nil || err != ErrNoAuth {
var msg string

if err == nil {
msg = "Fetching data without auth should have resulted in an error"
} else {
msg = fmt.Sprintf("Expecting ErrNoAuth, got `%+v` instead", err)
}
t.Fatalf(msg)
}

zk.AddAuth("digest", []byte("userfoo:passbar"))

_, _, err = zk.Get(testNode)
if err != nil {
t.Fatalf("Fetching data with auth failed: %+v", err)
}

ts.StopAllServers()
ts.StartAllServers()

_, _, err = zk.Get(testNode)
if err != nil {
t.Fatalf("Fetching data after reconnect failed: %+v", err)
}
}

func TestMultiFailures(t *testing.T) {
// This test case ensures that we return the errors associated with each
// opeThis in the event a call to Multi() fails.
Expand Down

0 comments on commit 5ccb459

Please sign in to comment.