-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Surface assessment tags on Archetype resource (#502)
* Use TagRefs on the Archetype resource * Add virtual tags inherited from assessments to the Tags field on the Archetype resource * Fixed a bug where an application would be denied membership in an archetype that wasn't a strict subset of another archetype. --------- Signed-off-by: Sam Lucidi <[email protected]>
- Loading branch information
Showing
7 changed files
with
150 additions
and
30 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
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,38 @@ | ||
package assessment | ||
|
||
import "github.com/konveyor/tackle2-hub/model" | ||
|
||
// | ||
// NewArchetypeResolver creates a new ArchetypeResolver. | ||
func NewArchetypeResolver(archetype *model.Archetype, tags *TagResolver) (a *ArchetypeResolver) { | ||
a = &ArchetypeResolver{ | ||
archetype: archetype, | ||
tagResolver: tags, | ||
} | ||
return | ||
} | ||
|
||
// | ||
// ArchetypeResolver wraps an Archetype model | ||
// with assessment-related functionality. | ||
type ArchetypeResolver struct { | ||
archetype *model.Archetype | ||
tagResolver *TagResolver | ||
} | ||
|
||
// | ||
// AssessmentTags returns the list of tags that the archetype should | ||
// inherit from the answers given to its assessments. | ||
func (r *ArchetypeResolver) AssessmentTags() (tags []model.Tag) { | ||
seenTags := make(map[uint]bool) | ||
for _, assessment := range r.archetype.Assessments { | ||
aTags := r.tagResolver.Assessment(&assessment) | ||
for _, t := range aTags { | ||
if _, found := seenTags[t.ID]; !found { | ||
seenTags[t.ID] = true | ||
tags = append(tags, t) | ||
} | ||
} | ||
} | ||
return | ||
} |
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
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,46 @@ | ||
package assessment | ||
|
||
import ( | ||
"github.com/onsi/gomega" | ||
"testing" | ||
) | ||
|
||
func TestSet_Superset(t *testing.T) { | ||
g := gomega.NewGomegaWithT(t) | ||
|
||
a := NewSet() | ||
b := NewSet() | ||
a.Add(1, 2, 3, 4) | ||
b.Add(1, 2, 3, 4) | ||
|
||
g.Expect(a.Superset(b, false)).To(gomega.BeTrue()) | ||
g.Expect(b.Superset(a, false)).To(gomega.BeTrue()) | ||
g.Expect(a.Superset(b, true)).To(gomega.BeFalse()) | ||
g.Expect(b.Superset(a, true)).To(gomega.BeFalse()) | ||
|
||
a.Add(5) | ||
g.Expect(a.Superset(b, false)).To(gomega.BeTrue()) | ||
g.Expect(a.Superset(b, true)).To(gomega.BeTrue()) | ||
g.Expect(b.Superset(a, false)).To(gomega.BeFalse()) | ||
g.Expect(b.Superset(a, true)).To(gomega.BeFalse()) | ||
} | ||
|
||
func TestSet_Subset(t *testing.T) { | ||
g := gomega.NewGomegaWithT(t) | ||
|
||
a := NewSet() | ||
b := NewSet() | ||
a.Add(1, 2, 3, 4) | ||
b.Add(1, 2, 3, 4) | ||
|
||
g.Expect(a.Subset(b, false)).To(gomega.BeTrue()) | ||
g.Expect(b.Subset(a, false)).To(gomega.BeTrue()) | ||
g.Expect(a.Subset(b, true)).To(gomega.BeFalse()) | ||
g.Expect(b.Subset(a, true)).To(gomega.BeFalse()) | ||
|
||
b.Add(5) | ||
g.Expect(a.Subset(b, false)).To(gomega.BeTrue()) | ||
g.Expect(a.Subset(b, true)).To(gomega.BeTrue()) | ||
g.Expect(b.Subset(a, false)).To(gomega.BeFalse()) | ||
g.Expect(b.Subset(a, true)).To(gomega.BeFalse()) | ||
} |