From b9833990c40430484a07330d82afb73b683d6a54 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Mon, 24 Apr 2017 15:33:43 +0800 Subject: [PATCH] bug fix --- src/common/dao/dao_test.go | 5 +++++ src/common/dao/user.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/common/dao/dao_test.go b/src/common/dao/dao_test.go index d3ea777b4..8f40406f2 100644 --- a/src/common/dao/dao_test.go +++ b/src/common/dao/dao_test.go @@ -22,6 +22,7 @@ import ( "github.com/astaxie/beego/orm" //"github.com/vmware/harbor/src/common/config" + "github.com/stretchr/testify/assert" "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/utils" "github.com/vmware/harbor/src/common/utils/log" @@ -402,6 +403,10 @@ func TestGetUser(t *testing.T) { if currentUser.Email != "tester01@vmware.com" { t.Errorf("the user's email does not match, expected: tester01@vmware.com, actual: %s", currentUser.Email) } + + queryUser = models.User{} + _, err = GetUser(queryUser) + assert.NotNil(t, err) } func TestListUsers(t *testing.T) { diff --git a/src/common/dao/user.go b/src/common/dao/user.go index 8f757a8a8..46f7fe29a 100644 --- a/src/common/dao/user.go +++ b/src/common/dao/user.go @@ -60,6 +60,10 @@ func GetUser(query models.User) (*models.User, error) { return nil, nil } + if n > 1 { + return nil, fmt.Errorf("got more than one user when executing: %s param: %v", sql, queryParam) + } + return &u[0], nil }