Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions internal/api/graphql/graph/resolver/mutation.go

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

48 changes: 43 additions & 5 deletions internal/database/mariadb/test/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,41 @@ func (s *SeedCollection) FindMatchingComponentVersionAndIssueVariant() (
return mariadb.ComponentVersionRow{}, mariadb.IssueVariantRow{}, false
}

func (s *SeedCollection) FindLinkedRemediationData() (mariadb.BaseServiceRow, mariadb.ComponentRow, mariadb.IssueRow, bool) {
for _, cvi := range s.ComponentVersionIssueRows {
ci, ok := lo.Find(s.ComponentInstanceRows, func(ci mariadb.ComponentInstanceRow) bool {
return ci.ComponentVersionId.Int64 == cvi.ComponentVersionId.Int64
})
if !ok {
continue
}

service, ok := s.GetServiceById(ci.ServiceId.Int64)
if !ok {
continue
}

cv, ok := s.GetComponentVersionById(cvi.ComponentVersionId.Int64)
if !ok {
continue
}

component, ok := s.GetComponentById(cv.ComponentId.Int64)
if !ok {
continue
}

issue, ok := s.GetIssueById(cvi.IssueId.Int64)
if !ok {
continue
}

return service, component, issue, true
}

return mariadb.BaseServiceRow{}, mariadb.ComponentRow{}, mariadb.IssueRow{}, false
}

func (s *SeedCollection) FindMatchingSupportGroupAndIssueMatch() (mariadb.SupportGroupRow, mariadb.IssueMatchRow, bool) {
for _, imRow := range s.IssueMatchRows {
ciRow, ok := s.GetComponentInstanceById(imRow.ComponentInstanceId.Int64)
Expand Down Expand Up @@ -893,6 +928,7 @@ func (s *DatabaseSeeder) SeedComponentVersions(
component := components[randomIndex]
componentVersion.ComponentId = component.Id
componentVersion.EndOfLife = sql.NullBool{Bool: []bool{true, false}[i%2], Valid: true}
componentVersion.Repository = component.Repository

componentVersionId, err := s.InsertFakeComponentVersion(componentVersion)
if err != nil {
Expand All @@ -914,10 +950,12 @@ func (s *DatabaseSeeder) SeedComponentInstances(
) []mariadb.ComponentInstanceRow {
var componentInstances []mariadb.ComponentInstanceRow

for range num {
limit := min(len(services), min(len(componentVersions), num))

for i := range limit {
componentInstance := NewFakeComponentInstance()
componentInstance.ComponentVersionId = PickOne(componentVersions).Id
componentInstance.ServiceId = PickOne(services).Id
componentInstance.ComponentVersionId = componentVersions[i].Id
componentInstance.ServiceId = services[i].Id

componentInstanceId, err := s.InsertFakeComponentInstance(componentInstance)
if err != nil {
Expand Down Expand Up @@ -982,8 +1020,8 @@ func (s *DatabaseSeeder) SeedComponentVersionIssues(
cviList := make([]mariadb.ComponentVersionIssueRow, num)
for i := range num {
cvi := NewFakeComponentVersionIssue()
cvi.IssueId = PickOne(issues).Id
cvi.ComponentVersionId = PickOne(componentVersions).Id
cvi.IssueId = issues[i].Id
cvi.ComponentVersionId = componentVersions[i].Id

_, err := s.InsertFakeComponentVersionIssue(cvi)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions internal/e2e/remediation_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ var _ = Describe("Creating Remediation via API", Label("e2e", "Remediations"), f
BeforeEach(func() {
seedCollection = seeder.SeedDbWithNFakeData(10)
remediation = testentity.NewFakeRemediationEntity()
remediation.Service = seedCollection.ServiceRows[0].CCRN.String
remediation.Component = seedCollection.ComponentRows[0].Repository.String
remediation.Issue = seedCollection.IssueRows[0].PrimaryName.String
service, component, issue, ok := seedCollection.FindLinkedRemediationData()
Expect(ok).To(BeTrue(), "linked service/component/issue data must exist in seed")
remediation.Service = service.CCRN.String
remediation.Component = component.Repository.String
remediation.Issue = issue.PrimaryName.String
})

Context("and a mutation query is performed", Label("create.graphql"), func() {
Expand Down
Loading