From eeee43d5697d8e12dc383f11952386a6a859b097 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Tue, 9 Nov 2021 19:29:56 +0800 Subject: [PATCH] Test: newly added sb models --- models/node_test.go | 2 +- models/policy_test.go | 15 +++++++++++++++ models/tag_test.go | 6 +++--- models/task_test.go | 11 +++++++++++ models/webdav_test.go | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/models/node_test.go b/models/node_test.go index ddc1f95..de1757f 100644 --- a/models/node_test.go +++ b/models/node_test.go @@ -48,7 +48,7 @@ func TestNode_BeforeSave(t *testing.T) { node.Aria2OptionsSerialized.Timeout = 1 a.NoError(node.BeforeSave()) - a.Contains("1", node.Aria2Options) + a.Contains(node.Aria2Options, "1") } func TestNode_SetStatus(t *testing.T) { diff --git a/models/policy_test.go b/models/policy_test.go index 91de270..433d1ec 100644 --- a/models/policy_test.go +++ b/models/policy_test.go @@ -327,3 +327,18 @@ func TestPolicy_IsThumbExist(t *testing.T) { asserts.Equal(testCase.expect, policy.IsThumbExist(testCase.name)) } } + +func TestPolicy_UpdateAccessKeyAndClearCache(t *testing.T) { + a := assert.New(t) + cache.Set("policy_1331", Policy{}, 3600) + p := &Policy{} + p.ID = 1331 + mock.ExpectBegin() + mock.ExpectExec("UPDATE(.+)").WithArgs("ak", sqlmock.AnyArg()).WillReturnResult(sqlmock.NewResult(1, 1)) + mock.ExpectCommit() + + a.NoError(p.UpdateAccessKeyAndClearCache("ak")) + a.NoError(mock.ExpectationsWereMet()) + _, ok := cache.Get("policy_1331") + a.False(ok) +} diff --git a/models/tag_test.go b/models/tag_test.go index 4ecdc5d..6063234 100644 --- a/models/tag_test.go +++ b/models/tag_test.go @@ -55,9 +55,9 @@ func TestGetTagsByUID(t *testing.T) { func TestGetTagsByID(t *testing.T) { asserts := assert.New(t) - mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) - res, err := GetTasksByID(1) + mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"name"}).AddRow("tag")) + res, err := GetTagsByUID(1) asserts.NoError(mock.ExpectationsWereMet()) asserts.NoError(err) - asserts.EqualValues(1, res.ID) + asserts.EqualValues("tag", res[0].Name) } diff --git a/models/task_test.go b/models/task_test.go index 167819a..1ad71c3 100644 --- a/models/task_test.go +++ b/models/task_test.go @@ -91,3 +91,14 @@ func TestListTasks(t *testing.T) { asserts.EqualValues(5, total) asserts.Len(res, 1) } + +func TestGetTasksByStatus(t *testing.T) { + a := assert.New(t) + + mock.ExpectQuery("SELECT(.+)"). + WithArgs(1, 2). + WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) + res := GetTasksByStatus(1, 2) + a.NoError(mock.ExpectationsWereMet()) + a.Len(res, 1) +} diff --git a/models/webdav_test.go b/models/webdav_test.go index 4570c5c..55a7326 100644 --- a/models/webdav_test.go +++ b/models/webdav_test.go @@ -55,6 +55,6 @@ func TestDeleteWebDAVAccountByID(t *testing.T) { mock.ExpectBegin() mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectCommit() - asserts.NoError(DeleteTagByID(1, 1)) + DeleteWebDAVAccountByID(1, 1) asserts.NoError(mock.ExpectationsWereMet()) }