Skip to content

Commit 855efde

Browse files
authored
feat(cdn): requires at least one storage that is not cds (#5747)
Signed-off-by: richardlt <[email protected]>
1 parent aef2102 commit 855efde

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

engine/cdn/cdn_sync_test.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cdn
22

33
import (
44
"context"
5+
"io/ioutil"
56
"testing"
67
"time"
78

@@ -29,6 +30,9 @@ func TestSyncBuffer(t *testing.T) {
2930
cdntest.ClearItem(t, context.Background(), m, db)
3031
cdntest.ClearUnits(t, context.Background(), m, db)
3132

33+
tmpDir, err := ioutil.TempDir("", t.Name()+"-cdn-*")
34+
require.NoError(t, err)
35+
3236
// Create cdn service
3337
s := Service{
3438
DBConnectionFactory: factory,
@@ -38,10 +42,6 @@ func TestSyncBuffer(t *testing.T) {
3842
GoRoutines: sdk.NewGoRoutines(),
3943
},
4044
}
41-
cdsConfig := &storage.CDSStorageConfiguration{
42-
Host: "http://lolcat.host:8081",
43-
Token: "mytoken",
44-
}
4545
cdnUnits, err := storage.Init(context.Background(), m, cache, db.DbMap, sdk.NewGoRoutines(), storage.Configuration{
4646
HashLocatorSalt: "thisismysalt",
4747
Buffers: map[string]storage.BufferConfiguration{
@@ -55,7 +55,15 @@ func TestSyncBuffer(t *testing.T) {
5555
},
5656
Storages: map[string]storage.StorageConfiguration{
5757
"test-cds-backend.TestSyncBuffer": {
58-
CDS: cdsConfig,
58+
CDS: &storage.CDSStorageConfiguration{
59+
Host: "http://lolcat.host:8081",
60+
Token: "mytoken",
61+
},
62+
},
63+
"test-local.TestSyncBuffer": {
64+
Local: &storage.LocalStorageConfiguration{
65+
Path: tmpDir,
66+
},
5967
},
6068
},
6169
})
@@ -92,14 +100,12 @@ func TestSyncLog(t *testing.T) {
92100
},
93101
}
94102

95-
cdsConfig := &storage.CDSStorageConfiguration{
96-
Host: "http://lolcat.host:8081",
97-
Token: "mytoken",
98-
}
99-
100103
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
101104
t.Cleanup(cancel)
102105

106+
tmpDir, err := ioutil.TempDir("", t.Name()+"-cdn-*")
107+
require.NoError(t, err)
108+
103109
cdnUnits, err := storage.Init(ctx, m, cache, db.DbMap, sdk.NewGoRoutines(), storage.Configuration{
104110
HashLocatorSalt: "thisismysalt",
105111
SyncNbElements: 100,
@@ -116,7 +122,15 @@ func TestSyncLog(t *testing.T) {
116122
},
117123
Storages: map[string]storage.StorageConfiguration{
118124
"test-cds-backend.TestSyncLog": {
119-
CDS: cdsConfig,
125+
CDS: &storage.CDSStorageConfiguration{
126+
Host: "http://lolcat.host:8081",
127+
Token: "mytoken",
128+
},
129+
},
130+
"test-local.TestSyncLog": {
131+
Local: &storage.LocalStorageConfiguration{
132+
Path: tmpDir,
133+
},
120134
},
121135
},
122136
})

engine/cdn/storage/storageunit.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,18 @@ func Init(ctx context.Context, m *gorpmapper.Mapper, store cache.Store, db *gorp
6767
countFileBuffer++
6868
}
6969
}
70-
if countLogBuffer == 0 || countLogBuffer > 1 {
70+
if countLogBuffer != 1 {
7171
return nil, sdk.WithStack(fmt.Errorf("missing or too much CDN Buffer for log items"))
7272
}
73+
// TODO set file buffer as required when CDN will be use by default for files
7374
if countFileBuffer > 1 {
7475
return nil, sdk.WithStack(fmt.Errorf("too much CDN Buffer for file items"))
7576
}
7677

78+
// We should have at least one storage backend that is not of type cds to store logs and artifacts
7779
activeStorage := 0
7880
for _, s := range config.Storages {
79-
if !s.DisableSync {
81+
if !s.DisableSync && s.CDS == nil {
8082
activeStorage++
8183
}
8284
}

0 commit comments

Comments
 (0)