generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copyonwrite/344/implement automatic detection of issues which can be …
…closed (#430) * Add dependency to gqlgen for targets test-db, test-app and test-e2e * Add ScannerRun table * Add/modify tables for ScannerRun and ScannerRunIssueTracker * Add uuid to ScannerRun * Add 'tag' to ScannerRun * Use size of 255 for varchar fields instead of 256 * Make UUID unique * Align SQL schema and ScannerRun with project conventions * Add serialization/deserialization from/to ScannerRun * Adapt ScannerRun table to heureka naming conventions * Create an instance of ScannerRun in the database * Fix persistance for ScannerRun and add entities for app layer * Add skeleton for ScannerRun on the app layer * First test for ScannerRun create * Add licence header * Add first draft of graphql api definition for ScannerRun * Add supporting code to create a new ScannerRun via GraphQL * Models for graphql for creating ScannerRun entities * Add e2e test to create a ScannerRun * Fix e2e test for creating ScannerRun * Automatic application of license header --------- Co-authored-by: License Bot <[email protected]>
- Loading branch information
1 parent
2eb43f0
commit 113e83d
Showing
21 changed files
with
581 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
internal/api/graphql/graph/queryCollection/scannerRun/create.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
mutation ($input: ScannerRunInput!) { | ||
createScannerRun ( | ||
input: $input | ||
) { | ||
id | ||
tag | ||
uuid | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
type ScannerRun implements Node { | ||
id: ID! | ||
uuid: String! | ||
tag: String! | ||
start_run: DateTime! | ||
end_run: DateTime! | ||
completed: Boolean! | ||
metadata: Metadata | ||
} | ||
|
||
input ScannerRunInput { | ||
uuid: String | ||
tag: String | ||
} | ||
|
||
type ScannerRunConnection implements Connection { | ||
totalCount: Int! | ||
edges: [ScannerRun] | ||
pageInfo: PageInfo | ||
} | ||
|
||
type ScannerRunEdge implements Edge { | ||
node: ScannerRun! | ||
cursor: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package scanner_run | ||
|
||
import ( | ||
"github.com/cloudoperators/heureka/internal/app/event" | ||
"github.com/cloudoperators/heureka/internal/entity" | ||
) | ||
|
||
const ( | ||
CreateScannerRunEventName event.EventName = "CreateScannerRun" | ||
) | ||
|
||
type CreateScannerRunEvent struct { | ||
ScannerRun *entity.ScannerRun | ||
} | ||
|
||
func (csr *CreateScannerRunEvent) Name() event.EventName { | ||
return CreateScannerRunEventName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package scanner_run | ||
|
||
import ( | ||
"github.com/cloudoperators/heureka/internal/app/event" | ||
"github.com/cloudoperators/heureka/internal/database" | ||
"github.com/cloudoperators/heureka/internal/entity" | ||
) | ||
|
||
type scannerRunHandler struct { | ||
database database.Database | ||
eventRegistry event.EventRegistry | ||
} | ||
|
||
func NewScannerRunHandler(db database.Database, er event.EventRegistry) ScannerRunHandler { | ||
return &scannerRunHandler{ | ||
database: db, | ||
eventRegistry: er, | ||
} | ||
} | ||
|
||
type ScannerRunHandlerError struct { | ||
msg string | ||
} | ||
|
||
func (srh *scannerRunHandler) CreateScannerRun(sr *entity.ScannerRun) (*entity.ScannerRun, error) { | ||
_, err := srh.database.CreateScannerRun(sr) | ||
|
||
if err != nil { | ||
return nil, &ScannerRunHandlerError{msg: "Error creating scanner run"} | ||
} | ||
|
||
srh.eventRegistry.PushEvent(&CreateScannerRunEvent{sr}) | ||
return sr, nil | ||
} | ||
|
||
func (srhe *ScannerRunHandlerError) Error() string { | ||
return srhe.msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package scanner_run | ||
|
||
import "github.com/cloudoperators/heureka/internal/entity" | ||
|
||
type ScannerRunHandler interface { | ||
CreateScannerRun(*entity.ScannerRun) (*entity.ScannerRun, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package scanner_run | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cloudoperators/heureka/internal/app/event" | ||
"github.com/cloudoperators/heureka/internal/entity/test" | ||
|
||
"github.com/cloudoperators/heureka/internal/entity" | ||
"github.com/cloudoperators/heureka/internal/mocks" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestServiceHandler(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Service Service Test Suite") | ||
} | ||
|
||
var er event.EventRegistry | ||
|
||
var _ = BeforeSuite(func() { | ||
db := mocks.NewMockDatabase(GinkgoT()) | ||
er = event.NewEventRegistry(db) | ||
}) | ||
|
||
var sre *entity.ScannerRun | ||
|
||
var _ = Describe("When creating ScannerRun", Label("app", "CreateScannerRun"), func() { | ||
var ( | ||
db *mocks.MockDatabase | ||
scannerRunHandler ScannerRunHandler | ||
) | ||
|
||
BeforeEach(func() { | ||
db = mocks.NewMockDatabase(GinkgoT()) | ||
sre = test.NewFakeScannerRunEntity() | ||
}) | ||
|
||
It("creates a scannerrun", func() { | ||
db.On("CreateScannerRun", sre).Return(sre, nil) | ||
|
||
scannerRunHandler = NewScannerRunHandler(db, er) | ||
scannerRunHandler.CreateScannerRun(sre) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.