-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsexport_job_store_test.go
117 lines (100 loc) · 2.64 KB
/
dsexport_job_store_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"context"
"encoding/json"
"fmt"
"testing"
cds "cloud.google.com/go/datastore"
"github.com/google/uuid"
"go.mercari.io/datastore/clouddatastore"
)
func TestDSExportJobStore_Lifecycle(t *testing.T) {
ctx := context.Background()
cdsc, err := cds.NewClient(ctx, uuid.New().String())
if err != nil {
t.Fatal(err)
}
ds, err := clouddatastore.FromClient(ctx, cdsc)
if err != nil {
t.Fatal(err)
}
s, err := NewDSExportJobStore(ctx, ds)
if err != nil {
t.Fatal(err)
}
req := DatastoreExportRequest{
ProjectID: "gcpugjp-dev",
OutputGCSFilePath: "gs://datastore-backup-gcpugjp-dev",
Kinds: []string{"PugEvent"},
}
body, err := json.Marshal(req)
if err != nil {
t.Fatal(err)
}
ds2bqJobID := s.NewDS2BQJobID(ctx)
{
job, err := s.Create(ctx, ds2bqJobID, string(body), req.ProjectID, []string{}, []string{"PugEvent"})
if err != nil {
t.Fatal(err)
}
if e, g := DSExportJobStatusDefault, job.Status; e != g {
t.Fatalf("want Status is %v but got %v", e, g)
}
if e, g := string(body), job.JobRequestBody; e != g {
t.Fatalf("want JobRequestBody is %v but got %v", e, g)
}
}
const dsExportJobID = "dummyDatastoreExportJobID"
{
job, err := s.StartExportJob(ctx, ds2bqJobID, dsExportJobID, 0)
if err != nil {
t.Fatal(err)
}
if e, g := DSExportJobStatusRunning, job.Status; e != g {
t.Fatalf("want Status is %v but got %v", e, g)
}
if e, g := dsExportJobID, job.DSExportJobIDs[0]; e != g {
t.Fatalf("want DSExportJobID is %v but got %v", e, g)
}
}
{
const msg = "failed operation..."
job, err := s.FinishExportJob(ctx, ds2bqJobID, DSExportJobStatusFailed, dsExportJobID, msg)
if err != nil {
t.Fatal(err)
}
if e, g := DSExportJobStatusFailed, job.Status; e != g {
t.Fatalf("want Status is %v but got %v", e, g)
}
if e, g := fmt.Sprintf("%s-_-%s", dsExportJobID, msg), job.DSExportResponseMessages[0]; e != g {
t.Fatalf("want Message is %v but got %v", e, g)
}
}
}
func TestDSExportJobStore_IncrementJobStatusCheckCount(t *testing.T) {
ctx := context.Background()
cdsc, err := cds.NewClient(ctx, uuid.New().String())
if err != nil {
t.Fatal(err)
}
ds, err := clouddatastore.FromClient(ctx, cdsc)
if err != nil {
t.Fatal(err)
}
s, err := NewDSExportJobStore(ctx, ds)
if err != nil {
t.Fatal(err)
}
ds2bqJobID := s.NewDS2BQJobID(ctx)
_, err = s.Create(ctx, ds2bqJobID, "", "", []string{}, []string{})
if err != nil {
t.Fatal(err)
}
job, err := s.IncrementJobStatusCheckCount(ctx, ds2bqJobID)
if err != nil {
t.Fatal(err)
}
if e, g := 1, job.StatusCheckCount; e != g {
t.Errorf("want StatusCheckCount is %v but got %v", e, g)
}
}