Skip to content

Commit 24c6480

Browse files
Ensure no net changes to swagger
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
1 parent e13704f commit 24c6480

File tree

14 files changed

+58
-39
lines changed

14 files changed

+58
-39
lines changed

internal/apiserver/route_get_token_transfers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var getTokenTransfers = &ffapi.Route{
4343
filter := r.Filter
4444
if fromOrTo, ok := r.QP["fromOrTo"]; ok {
4545
fb := database.TokenTransferQueryFactory.NewFilter(cr.ctx)
46-
filter.Condition(
46+
filter = filter.Condition(
4747
fb.Or().
4848
Condition(fb.Eq("from", fromOrTo)).
4949
Condition(fb.Eq("to", fromOrTo)))

internal/apiserver/route_get_token_transfers_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package apiserver
1818

1919
import (
2020
"net/http/httptest"
21+
"strings"
2122
"testing"
2223

2324
"github.com/hyperledger/firefly-common/pkg/ffapi"
@@ -53,8 +54,9 @@ func TestGetTokenTransfersFromOrTo(t *testing.T) {
5354
res := httptest.NewRecorder()
5455

5556
mam.On("GetTokenTransfers", mock.Anything, mock.MatchedBy(func(filter ffapi.AndFilter) bool {
56-
info, _ := filter.Finalize()
57-
return info.String() == "( ( from == '0x1' ) || ( to == '0x1' ) )"
57+
f, _ := filter.Finalize()
58+
filterStr := f.String()
59+
return strings.Contains(filterStr, "( ( from == '0x1' ) || ( to == '0x1' ) )")
5860
})).Return([]*core.TokenTransfer{}, nil, nil)
5961
r.ServeHTTP(res, req)
6062

internal/apiserver/server.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ type Server interface {
5757

5858
type apiServer struct {
5959
// Defaults set with config
60-
defaultFilterLimit uint64
61-
maxFilterLimit uint64
62-
maxFilterSkip uint64
63-
apiTimeout time.Duration
64-
apiMaxTimeout time.Duration
65-
metricsEnabled bool
66-
ffiSwaggerGen FFISwaggerGen
60+
apiTimeout time.Duration
61+
apiMaxTimeout time.Duration
62+
metricsEnabled bool
63+
ffiSwaggerGen FFISwaggerGen
6764
}
6865

6966
func InitConfig() {
@@ -76,13 +73,10 @@ func InitConfig() {
7673

7774
func NewAPIServer() Server {
7875
return &apiServer{
79-
defaultFilterLimit: uint64(config.GetUint(coreconfig.APIDefaultFilterLimit)),
80-
maxFilterLimit: uint64(config.GetUint(coreconfig.APIMaxFilterLimit)),
81-
maxFilterSkip: uint64(config.GetUint(coreconfig.APIMaxFilterSkip)),
82-
apiTimeout: config.GetDuration(coreconfig.APIRequestTimeout),
83-
apiMaxTimeout: config.GetDuration(coreconfig.APIRequestMaxTimeout),
84-
metricsEnabled: config.GetBool(coreconfig.MetricsEnabled),
85-
ffiSwaggerGen: NewFFISwaggerGen(),
76+
apiTimeout: config.GetDuration(coreconfig.APIRequestTimeout),
77+
apiMaxTimeout: config.GetDuration(coreconfig.APIRequestMaxTimeout),
78+
metricsEnabled: config.GetBool(coreconfig.MetricsEnabled),
79+
ffiSwaggerGen: NewFFISwaggerGen(),
8680
}
8781
}
8882

@@ -158,6 +152,9 @@ func (as *apiServer) swaggerGenConf(apiBaseURL string) *ffapi.Options {
158152
Version: "1.0",
159153
PanicOnMissingDescription: config.GetBool(coreconfig.APIOASPanicOnMissingDescription),
160154
DefaultRequestTimeout: config.GetDuration(coreconfig.APIRequestTimeout),
155+
APIDefaultFilterLimit: config.GetString(coreconfig.APIDefaultFilterLimit),
156+
APIMaxFilterLimit: config.GetUint(coreconfig.APIMaxFilterLimit),
157+
APIMaxFilterSkip: config.GetUint(coreconfig.APIMaxFilterSkip),
161158
}
162159
}
163160

@@ -289,6 +286,9 @@ func (as *apiServer) routeHandler(hf *ffapi.HandlerFactory, mgr namespace.Manage
289286

290287
func (as *apiServer) handlerFactory() *ffapi.HandlerFactory {
291288
return &ffapi.HandlerFactory{
289+
DefaultFilterLimit: uint64(config.GetUint(coreconfig.APIDefaultFilterLimit)),
290+
MaxFilterLimit: uint64(config.GetUint(coreconfig.APIMaxFilterLimit)),
291+
MaxFilterSkip: uint64(config.GetUint(coreconfig.APIMaxFilterSkip)),
292292
DefaultRequestTimeout: config.GetDuration(coreconfig.APIRequestTimeout),
293293
MaxTimeout: config.GetDuration(coreconfig.APIRequestMaxTimeout),
294294
}

internal/apiserver/server_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func newTestServer() (*namespacemocks.Manager, *orchestratormocks.Orchestrator,
5656
mgr.On("Orchestrator", "default").Return(o).Maybe()
5757
mgr.On("Orchestrator", "mynamespace").Return(o).Maybe()
5858
mgr.On("Orchestrator", "ns1").Return(o).Maybe()
59+
config.Set(coreconfig.APIMaxFilterLimit, 100)
5960
as := &apiServer{
60-
apiTimeout: 5 * time.Second,
61-
maxFilterLimit: 100,
62-
ffiSwaggerGen: &apiservermocks.FFISwaggerGen{},
61+
apiTimeout: 5 * time.Second,
62+
ffiSwaggerGen: &apiservermocks.FFISwaggerGen{},
6363
}
6464
return mgr, o, as
6565
}
@@ -204,7 +204,7 @@ func TestFilterTooMany(t *testing.T) {
204204
assert.Equal(t, 400, res.Result().StatusCode)
205205
var resJSON map[string]interface{}
206206
json.NewDecoder(res.Body).Decode(&resJSON)
207-
assert.Regexp(t, "FF10184", resJSON["error"])
207+
assert.Regexp(t, "FF00192", resJSON["error"])
208208
}
209209

210210
func TestUnauthorized(t *testing.T) {

internal/apiserver/swagger_check_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
)
3939

4040
func TestDiffSwaggerYAML(t *testing.T) {
41+
coreconfig.Reset()
4142
config.Set(coreconfig.APIOASPanicOnMissingDescription, true)
4243
as := &apiServer{}
4344
hf := as.handlerFactory()

internal/apiserver/swagger_generate_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
)
3737

3838
func TestDownloadSwaggerYAML(t *testing.T) {
39+
coreconfig.Reset()
3940
config.Set(coreconfig.APIOASPanicOnMissingDescription, true)
4041
as := &apiServer{}
4142
hf := as.handlerFactory()

internal/broadcast/operations_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222
"strings"
2323
"testing"
2424

25+
"github.com/hyperledger/firefly-common/pkg/ffapi"
2526
"github.com/hyperledger/firefly-common/pkg/fftypes"
2627
"github.com/hyperledger/firefly/mocks/databasemocks"
2728
"github.com/hyperledger/firefly/mocks/dataexchangemocks"
2829
"github.com/hyperledger/firefly/mocks/datamocks"
2930
"github.com/hyperledger/firefly/mocks/sharedstoragemocks"
3031
"github.com/hyperledger/firefly/pkg/core"
31-
"github.com/hyperledger/firefly/pkg/database"
3232
"github.com/stretchr/testify/assert"
3333
"github.com/stretchr/testify/mock"
3434
)
@@ -258,7 +258,7 @@ func TestPrepareAndRunUploadBlob(t *testing.T) {
258258
mdi.On("GetBlobMatchingHash", mock.Anything, blob.Hash).Return(blob, nil)
259259
mps.On("UploadData", context.Background(), mock.Anything).Return("123", nil)
260260
mdx.On("DownloadBlob", context.Background(), mock.Anything).Return(reader, nil)
261-
mdi.On("UpdateData", context.Background(), "ns1", data.ID, mock.MatchedBy(func(update database.Update) bool {
261+
mdi.On("UpdateData", context.Background(), "ns1", data.ID, mock.MatchedBy(func(update ffapi.Update) bool {
262262
info, _ := update.Finalize()
263263
assert.Equal(t, 1, len(info.SetOperations))
264264
assert.Equal(t, "blob.public", info.SetOperations[0].Field)
@@ -302,7 +302,7 @@ func TestPrepareAndRunValue(t *testing.T) {
302302

303303
mdi.On("GetDataByID", mock.Anything, "ns1", data.ID, false).Return(data, nil)
304304
mps.On("UploadData", context.Background(), mock.Anything).Return("123", nil)
305-
mdi.On("UpdateData", context.Background(), "ns1", data.ID, mock.MatchedBy(func(update database.Update) bool {
305+
mdi.On("UpdateData", context.Background(), "ns1", data.ID, mock.MatchedBy(func(update ffapi.Update) bool {
306306
info, _ := update.Finalize()
307307
assert.Equal(t, 1, len(info.SetOperations))
308308
assert.Equal(t, "public", info.SetOperations[0].Field)

internal/data/message_writer_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/hyperledger/firefly-common/pkg/ffapi"
2627
"github.com/hyperledger/firefly-common/pkg/fftypes"
2728
"github.com/hyperledger/firefly/mocks/databasemocks"
2829
"github.com/hyperledger/firefly/pkg/core"
@@ -178,11 +179,11 @@ func TestPersistMWBatchIdempotencyAllFail(t *testing.T) {
178179
}).Return(nil)
179180
mdi.On("InsertDataArray", customCtx, append(m1d, m2d...)).Return(nil)
180181
mdi.On("InsertMessages", customCtx, []*core.Message{m1, m2}).Return(fmt.Errorf("various keys were not unique"))
181-
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f database.Filter) bool {
182+
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f ffapi.Filter) bool {
182183
ff, _ := f.Finalize()
183184
return strings.Contains(ff.String(), "idem1")
184185
})).Return([]*core.Message{m1}, nil, nil)
185-
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f database.Filter) bool {
186+
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f ffapi.Filter) bool {
186187
ff, _ := f.Finalize()
187188
return strings.Contains(ff.String(), "idem2")
188189
})).Return([]*core.Message{m2}, nil, nil)
@@ -237,11 +238,11 @@ func TestPersistMWBatchHalfFailResubmit(t *testing.T) {
237238
}).Return(nil)
238239
mdi.On("InsertDataArray", customCtx, append(m1d, m2d...)).Return(nil)
239240
mdi.On("InsertMessages", customCtx, []*core.Message{m1, m2}).Return(fmt.Errorf("various keys were not unique"))
240-
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f database.Filter) bool {
241+
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f ffapi.Filter) bool {
241242
ff, _ := f.Finalize()
242243
return strings.Contains(ff.String(), "idem1")
243244
})).Return([]*core.Message{}, nil, nil) // no result
244-
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f database.Filter) bool {
245+
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f ffapi.Filter) bool {
245246
ff, _ := f.Finalize()
246247
return strings.Contains(ff.String(), "idem2")
247248
})).Return([]*core.Message{m2}, nil, nil) // found result
@@ -286,7 +287,7 @@ func TestPersistMWBatchFailIdemCheck(t *testing.T) {
286287
}).Return(nil)
287288
mdi.On("InsertDataArray", customCtx, m1d).Return(nil)
288289
mdi.On("InsertMessages", customCtx, []*core.Message{m1}).Return(fmt.Errorf("failure1... which leads to..."))
289-
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f database.Filter) bool {
290+
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f ffapi.Filter) bool {
290291
ff, _ := f.Finalize()
291292
return strings.Contains(ff.String(), "idem1")
292293
})).Return([]*core.Message{}, nil, fmt.Errorf("failure1"))
@@ -359,7 +360,7 @@ func TestWriteMessageNoWorkersIdempotencyDuplicate(t *testing.T) {
359360
rag.Return(args[1].(func(context.Context) error)(customCtx))
360361
}).Return(nil)
361362
mdi.On("InsertMessages", customCtx, []*core.Message{&m1.Message}).Return(fmt.Errorf("failure1... which leads to..."))
362-
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f database.Filter) bool {
363+
mdi.On("GetMessages", mock.Anything, "ns1", mock.MatchedBy(func(f ffapi.Filter) bool {
363364
ff, _ := f.Finalize()
364365
return strings.Contains(ff.String(), "idem1")
365366
})).Return([]*core.Message{

internal/database/postgres/postgres.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
migratedb "github.com/golang-migrate/migrate/v4/database"
2828
"github.com/golang-migrate/migrate/v4/database/postgres"
2929
"github.com/hyperledger/firefly-common/pkg/config"
30+
"github.com/hyperledger/firefly-common/pkg/dbsql"
3031
"github.com/hyperledger/firefly/internal/database/sqlcommon"
3132
"github.com/hyperledger/firefly/pkg/database"
3233

@@ -51,6 +52,10 @@ func (psql *Postgres) Name() string {
5152
return "postgres"
5253
}
5354

55+
func (psql *Postgres) SequenceColumn() string {
56+
return "seq"
57+
}
58+
5459
func (psql *Postgres) MigrationsDir() string {
5560
return psql.Name()
5661
}
@@ -64,8 +69,8 @@ func lockIndex(lockName string) int64 {
6469
return big.NewInt(0).SetBytes([]byte(lockName)).Int64()
6570
}
6671

67-
func (psql *Postgres) Features() sqlcommon.SQLFeatures {
68-
features := sqlcommon.DefaultSQLProviderFeatures()
72+
func (psql *Postgres) Features() dbsql.SQLFeatures {
73+
features := dbsql.DefaultSQLProviderFeatures()
6974
features.PlaceholderFormat = sq.Dollar
7075
features.UseILIKE = false // slower than lower()
7176
features.AcquireLock = func(lockName string) string {

internal/database/postgres/postgres_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestPostgresProvider(t *testing.T) {
3939
assert.Error(t, err)
4040

4141
assert.Equal(t, "postgres", psql.Name())
42+
assert.Equal(t, "seq", psql.SequenceColumn())
4243
assert.Equal(t, sq.Dollar, psql.Features().PlaceholderFormat)
4344
assert.Equal(t, `SELECT pg_advisory_xact_lock(8387236824920056683);`, psql.Features().AcquireLock("test-lock"))
4445
assert.Equal(t, `SELECT pg_advisory_xact_lock(116);`, psql.Features().AcquireLock("t"))

0 commit comments

Comments
 (0)