From 8c87916f686ce86825f28ea60663df615a9118a9 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Tue, 14 Feb 2017 14:39:51 -0800 Subject: [PATCH] auth: add 'setupAuthStore' to tests --- auth/store_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/auth/store_test.go b/auth/store_test.go index 62ded405f..ebe8ef122 100644 --- a/auth/store_test.go +++ b/auth/store_test.go @@ -330,3 +330,32 @@ func contains(array []string, str string) bool { } return false } + +func setupAuthStore(t *testing.T) (store *authStore, teardownfunc func(t *testing.T)) { + b, tPath := backend.NewDefaultTmpBackend() + + as := NewAuthStore(b, dummyIndexWaiter) + err := enableAuthAndCreateRoot(as) + if err != nil { + t.Fatal(err) + } + + // adds a new role + _, err = as.RoleAdd(&pb.AuthRoleAddRequest{Name: "role-test"}) + if err != nil { + t.Fatal(err) + } + + ua := &pb.AuthUserAddRequest{Name: "foo", Password: "bar"} + _, err = as.UserAdd(ua) // add a non-existing user + if err != nil { + t.Fatal(err) + } + + tearDown := func(t *testing.T) { + b.Close() + os.Remove(tPath) + as.Close() + } + return as, tearDown +}