Skip to content

Commit 20f5e72

Browse files
committed
fix pkgs' models, fix tests
1 parent e2e7d2e commit 20f5e72

17 files changed

+74
-47
lines changed

pkg/alvax/controllers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ func TestPostDumpRestore(t *testing.T) {
141141
r.ServeHTTP(w, req)
142142

143143
var ret = struct {
144-
Count int `json:"count"`
144+
Count []int `json:"count"`
145145
}{}
146146
json.Unmarshal(w.Body.Bytes(), &ret)
147147

148148
//t.Logf("%s", jsonValue)
149149

150150
assert.Equal(t, http.StatusCreated, w.Code)
151-
assert.Equal(t, 1, ret.Count)
151+
assert.Equal(t, []int{1}, ret.Count)
152152
}

pkg/backups/controllers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ func TestPostDumpRestore(t *testing.T) {
149149
r.ServeHTTP(w, req)
150150

151151
var ret = struct {
152-
Count int `json:"count"`
152+
Count []int `json:"count"`
153153
}{}
154154
json.Unmarshal(w.Body.Bytes(), &ret)
155155

156156
//t.Logf("%s", jsonValue)
157157

158158
assert.Equal(t, http.StatusCreated, w.Code)
159-
assert.Equal(t, 1, ret.Count)
159+
assert.Equal(t, []int{1}, ret.Count)
160160
}
161161

162162
func TestActiveToggleBackupByServiceKey(t *testing.T) {

pkg/business/controllers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ func TestPostDumpRestore(t *testing.T) {
144144
r.ServeHTTP(w, req)
145145

146146
var ret = struct {
147-
Count int `json:"count"`
147+
Count []int `json:"count"`
148148
}{}
149149
json.Unmarshal(w.Body.Bytes(), &ret)
150150

151151
assert.Equal(t, http.StatusCreated, w.Code)
152-
assert.Equal(t, 1, ret.Count)
152+
assert.Equal(t, []int{1}, ret.Count)
153153
}

pkg/depots/controllers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ func TestPostDumpRestore(t *testing.T) {
144144
r.ServeHTTP(w, req)
145145

146146
var ret = struct {
147-
Count int `json:"count"`
147+
Count []int `json:"count"`
148148
}{}
149149
json.Unmarshal(w.Body.Bytes(), &ret)
150150

151151
assert.Equal(t, http.StatusCreated, w.Code)
152-
assert.Equal(t, 1, ret.Count)
152+
assert.Equal(t, []int{1}, ret.Count)
153153
}

pkg/dish/controllers.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ var Package *core.Package = &core.Package{
3838
}
3939

4040
var restorePackage = &core.RestorePackage{
41-
Name: pkgName,
42-
Cache: caches,
43-
CacheNames: []string{"CacheIncidents", "CacheSockets", "CacheStreamer"},
44-
Subpackages: []string{"incidents", "sockets"},
41+
Name: pkgName,
42+
Cache: caches,
43+
CacheNames: []string{
44+
"CacheIncidents",
45+
"CacheSockets",
46+
"CacheStreamer",
47+
},
48+
Subpackages: []string{
49+
"incidents",
50+
"sockets",
51+
},
4552
SubpackageModels: map[string]any{
4653
"incidents": Incident{},
4754
"sockets": Socket{},

pkg/dish/controllers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestPostDumpRestore(t *testing.T) {
7474
r.ServeHTTP(w, req)
7575

7676
var ret = struct {
77-
Count []int `json:"counter"`
77+
Count []int `json:"count"`
7878
}{}
7979
json.Unmarshal(w.Body.Bytes(), &ret)
8080

pkg/finance/controllers.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ var Package *core.Package = &core.Package{
3131
}
3232

3333
var restorePackage = &core.RestorePackage{
34-
Name: pkgName,
35-
Cache: caches,
36-
CacheNames: []string{"CacheAccounts", "CacheItems"},
37-
Subpackages: []string{"accounts", "items"},
34+
Name: pkgName,
35+
Cache: caches,
36+
CacheNames: []string{
37+
"CacheAccounts",
38+
"CacheItems",
39+
},
40+
Subpackages: []string{
41+
"accounts",
42+
"items",
43+
},
3844
SubpackageModels: map[string]any{
3945
"accounts": Account{},
4046
"items": Item{},
@@ -443,6 +449,11 @@ func GetRootData(ctx *gin.Context) {
443449
// @Produce json
444450
// @Router /finance/restore [post]
445451
func PostDumpRestore(ctx *gin.Context) {
452+
core.BatchRestoreItems[FinanceRoot](ctx, restorePackage)
453+
return
454+
}
455+
456+
func PostDumpRestore2(ctx *gin.Context) {
446457
var counter []int = []int{0, 0}
447458

448459
var importFinance = struct {

pkg/finance/controllers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestPostDumpRestore(t *testing.T) {
7777
r.ServeHTTP(w, req)
7878

7979
var ret = struct {
80-
Count []int `json:"counter"`
80+
Count []int `json:"count"`
8181
}{}
8282
json.Unmarshal(w.Body.Bytes(), &ret)
8383

@@ -157,7 +157,7 @@ func TestGetAccounts(t *testing.T) {
157157

158158
assert.Equal(t, http.StatusOK, w.Code)
159159

160-
// number 2 down below is wrong, see notes above (cca L87)
160+
// TODO: number 2 there is not correct, the "invalid" account should not be imported
161161
assert.Equal(t, 2, items.Count)
162162
assert.NotEmpty(t, items.Accounts)
163163
}
@@ -295,7 +295,7 @@ func TestGetItemsByAccountID(t *testing.T) {
295295
json.Unmarshal(w.Body.Bytes(), &items)
296296

297297
assert.Equal(t, http.StatusOK, w.Code)
298-
assert.Equal(t, 2, items.Count)
298+
assert.Equal(t, 1, items.Count)
299299
assert.NotEmpty(t, items.Items)
300300
}
301301

pkg/finance/models.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import (
44
"time"
55
)
66

7+
type FinanceRoot struct {
8+
Accounts map[string]Account `json:"accounts"`
9+
Items map[string]Item `json:"items"`
10+
}
11+
712
type Account struct {
813
// Account unique ID, snake_cased identifier.
914
ID string `json:"id" binding:"required" required:"true" readonly:"true"`

pkg/infra/controllers.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ var Package *core.Package = &core.Package{
3434
}
3535

3636
var restorePackage = &core.RestorePackage{
37-
Name: pkgName,
38-
Cache: caches,
39-
CacheNames: []string{"Cache"},
37+
Name: pkgName,
38+
Cache: caches,
39+
CacheNames: []string{
40+
"CacheDomains",
41+
"CacheḦosts",
42+
"CacheNetworks",
43+
},
4044
Subpackages: []string{
4145
"domains",
4246
"hosts",

0 commit comments

Comments
 (0)