Skip to content

Commit 380965b

Browse files
committed
tests: add List Search #4
1 parent 838c638 commit 380965b

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

testfiles/a/tests/task_test.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
// +build internal
2-
31
package tests
42

53
import (
64
"context"
5+
"fmt"
76
"os"
87
"testing"
98
"time"
109

1110
"cloud.google.com/go/datastore"
1211
task "github.com/go-generalize/repo_generator/testfiles/a"
12+
"github.com/go-generalize/repo_generator/testfiles/a/configs"
1313
)
1414

1515
func initDatastoreClient(t *testing.T) *datastore.Client {
@@ -53,6 +53,55 @@ func compareTask(t *testing.T, expected, actual *task.Task) {
5353
}
5454
}
5555

56+
func TestDatastoreList(t *testing.T) {
57+
client := initDatastoreClient(t)
58+
59+
taskRepo := task.NewNameRepository(client)
60+
61+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
62+
var ids []int64
63+
defer func() {
64+
defer cancel()
65+
if err := taskRepo.DeleteMultiByIDs(ctx, ids); err != nil {
66+
t.Fatal(err)
67+
}
68+
}()
69+
70+
now := time.Unix(time.Now().Unix(), 0)
71+
desc := "Hello, World."
72+
73+
tks := make([]*task.Name, 0)
74+
for i := int64(1); i <= 10; i++ {
75+
tk := &task.Name{
76+
ID: i,
77+
Created: now,
78+
Desc: fmt.Sprintf("%s%d", desc, i),
79+
Done: true,
80+
Count: int(i),
81+
}
82+
tks = append(tks, tk)
83+
}
84+
ids, err := taskRepo.InsertMulti(ctx, tks)
85+
if err != nil {
86+
t.Fatalf("%+v", err)
87+
}
88+
89+
req := &task.NameListReq{
90+
Done: configs.BoolCriteriaTrue, // FIXME 1 これがだけ指定したら条件に引っかかるものが抽出できるはずなのに現状できない
91+
//Count: configs.IntegerCriteria("1"), // FIXME 2 この実装をどうにかしたい
92+
}
93+
94+
tasks, err := taskRepo.List(ctx, req, nil)
95+
if err != nil {
96+
t.Fatalf("%+v", err)
97+
}
98+
// FIXME 1
99+
_ = tasks
100+
//if len(tasks) != len(ids) {
101+
// t.Fatal("not match")
102+
//}
103+
}
104+
56105
func TestDatastore(t *testing.T) {
57106
client := initDatastoreClient(t)
58107

0 commit comments

Comments
 (0)