Skip to content

Commit

Permalink
Require project ID when listing data source rules
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherias committed Jan 15, 2025
1 parent 10ab63b commit df1593b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
8 changes: 4 additions & 4 deletions database/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion database/query/datasources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ WHERE data_source_id = $1 AND project_id = $2;
--
-- name: ListRuleTypesReferencesByDataSource :many
SELECT * FROM rule_type_data_sources
WHERE data_sources_id = $1;
WHERE data_sources_id = $1 and project_id = $2;

-- AddRuleTypeDataSourceReference adds a link between one rule type
-- and one data source it uses.
Expand Down
5 changes: 4 additions & 1 deletion internal/datasources/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ func (d *dataSourceService) Delete(
tx := stx.Q()

// List rule types referencing the data source
ret, err := tx.ListRuleTypesReferencesByDataSource(ctx, id)
ret, err := tx.ListRuleTypesReferencesByDataSource(ctx, db.ListRuleTypesReferencesByDataSourceParams{
DataSourcesID: id,
ProjectID: project,
})
if err != nil {
return fmt.Errorf("failed to list rule types referencing data source %s: %w", id, err)
}
Expand Down
30 changes: 24 additions & 6 deletions internal/datasources/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,10 @@ func TestDelete(t *testing.T) {
setup: func(args args, mockDB *mockdb.MockStore) {
// Mock ListRuleTypesReferencesByDataSource to return empty list
mockDB.EXPECT().
ListRuleTypesReferencesByDataSource(gomock.Any(), args.id).
ListRuleTypesReferencesByDataSource(gomock.Any(), db.ListRuleTypesReferencesByDataSourceParams{
DataSourcesID: args.id,
ProjectID: args.project,
}).
Return([]db.RuleTypeDataSource{}, nil)

mockDB.EXPECT().
Expand Down Expand Up @@ -951,7 +954,10 @@ func TestDelete(t *testing.T) {
setup: func(args args, mockDB *mockdb.MockStore) {
// Mock ListRuleTypesReferencesByDataSource to return empty list
mockDB.EXPECT().
ListRuleTypesReferencesByDataSource(gomock.Any(), args.id).
ListRuleTypesReferencesByDataSource(gomock.Any(), db.ListRuleTypesReferencesByDataSourceParams{
DataSourcesID: args.id,
ProjectID: args.project,
}).
Return([]db.RuleTypeDataSource{}, nil)

mockDB.EXPECT().
Expand Down Expand Up @@ -981,7 +987,10 @@ func TestDelete(t *testing.T) {
setup: func(args args, mockDB *mockdb.MockStore) {
// Mock ListRuleTypesReferencesByDataSource to return non-empty list
mockDB.EXPECT().
ListRuleTypesReferencesByDataSource(gomock.Any(), args.id).
ListRuleTypesReferencesByDataSource(gomock.Any(), db.ListRuleTypesReferencesByDataSourceParams{
DataSourcesID: args.id,
ProjectID: args.project,
}).
Return([]db.RuleTypeDataSource{
{RuleTypeID: uuid.New()},
}, nil)
Expand All @@ -997,7 +1006,10 @@ func TestDelete(t *testing.T) {
},
setup: func(args args, mockDB *mockdb.MockStore) {
mockDB.EXPECT().
ListRuleTypesReferencesByDataSource(gomock.Any(), args.id).
ListRuleTypesReferencesByDataSource(gomock.Any(), db.ListRuleTypesReferencesByDataSourceParams{
DataSourcesID: args.id,
ProjectID: args.project,
}).
Return([]db.RuleTypeDataSource{}, nil)
mockDB.EXPECT().
GetDataSource(gomock.Any(), gomock.Any()).
Expand All @@ -1018,7 +1030,10 @@ func TestDelete(t *testing.T) {
setup: func(args args, mockDB *mockdb.MockStore) {
// Mock ListRuleTypesReferencesByDataSource to return an error
mockDB.EXPECT().
ListRuleTypesReferencesByDataSource(gomock.Any(), args.id).
ListRuleTypesReferencesByDataSource(gomock.Any(), db.ListRuleTypesReferencesByDataSourceParams{
DataSourcesID: args.id,
ProjectID: args.project,
}).
Return(nil, fmt.Errorf("database error"))
},
wantErr: true,
Expand All @@ -1033,7 +1048,10 @@ func TestDelete(t *testing.T) {
setup: func(args args, mockDB *mockdb.MockStore) {
// Mock ListRuleTypesReferencesByDataSource to return empty list
mockDB.EXPECT().
ListRuleTypesReferencesByDataSource(gomock.Any(), args.id).
ListRuleTypesReferencesByDataSource(gomock.Any(), db.ListRuleTypesReferencesByDataSourceParams{
DataSourcesID: args.id,
ProjectID: args.project,
}).
Return([]db.RuleTypeDataSource{}, nil)
mockDB.EXPECT().
GetDataSource(gomock.Any(), gomock.Any()).
Expand Down
11 changes: 8 additions & 3 deletions internal/db/datasources.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/db/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df1593b

Please sign in to comment.