Skip to content

Commit

Permalink
Update Tags in analysis test
Browse files Browse the repository at this point in the history
Re-enabled check of Analysis Tags and updated expected Tags with their
Category.

Updated error outputs for better readability.

Related to konveyor#31

Signed-off-by: Marek Aufart <maufart@redhat.com>
  • Loading branch information
aufi committed Sep 22, 2023
1 parent 9afeb60 commit a9aad55
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
61 changes: 27 additions & 34 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ func TestApplicationAnalysis(t *testing.T) {
// Check the analysis issues
if len(gotAnalysis.Issues) != len(tc.Analysis.Issues) {
t.Errorf("Different amount of issues error. Got %d, expected %d.", len(gotAnalysis.Issues), len(tc.Analysis.Issues))
t.Errorf("Got: %+v\nExpected: %+v.\n", gotAnalysis.Issues, tc.Analysis.Issues)
} else {
for i, got := range gotAnalysis.Issues {
expected := tc.Analysis.Issues[i]
if got.Category != expected.Category || got.RuleSet != expected.RuleSet || got.Rule != expected.Rule || got.Effort != expected.Effort || !strings.HasPrefix(got.Description, expected.Description) {
t.Errorf("\nDifferent issue error. Got %+v, expected %+v.\n\n", got, expected)
t.Errorf("\nDifferent issue error. Got %+v\nExpected %+v.\n\n", got, expected)
}

// Incidents check.
Expand All @@ -143,14 +144,15 @@ func TestApplicationAnalysis(t *testing.T) {
}
if len(got.Incidents) != len(expected.Incidents) {
t.Errorf("Different amount of incidents error. Got %d, expected %d.", len(got.Incidents), len(expected.Incidents))
t.Errorf("Got: %+v\nExpected: %+v.\n", got.Incidents, expected.Incidents)
} else {
// Ensure stable order of Incidents.
sort.SliceStable(got.Incidents, func(a, b int) bool { return got.Incidents[a].File < got.Incidents[b].File })
sort.SliceStable(expected.Incidents, func(a, b int) bool { return expected.Incidents[a].File < expected.Incidents[b].File })
for j, gotInc := range got.Incidents {
expectedInc := expected.Incidents[j]
if gotInc.File != expectedInc.File || gotInc.Line != expectedInc.Line || !strings.HasPrefix(gotInc.Message, expectedInc.Message) {
t.Errorf("\nDifferent incident error. Got %+v, expected %+v.\n\n", gotInc, expectedInc)
t.Errorf("\nDifferent incident error. Got %+v\nExpected %+v.\n\n", gotInc, expectedInc)
}
}
}
Expand All @@ -164,53 +166,44 @@ func TestApplicationAnalysis(t *testing.T) {
// Check the dependencies.
if len(gotAnalysis.Dependencies) != len(tc.Analysis.Dependencies) {
t.Errorf("Different amount of dependencies error. Got %d, expected %d.", len(gotAnalysis.Dependencies), len(tc.Analysis.Dependencies))
t.Errorf("Got: %+v\nExpected: %+v.\n", gotAnalysis.Dependencies, tc.Analysis.Dependencies)
} else {
for i, got := range gotAnalysis.Dependencies {
expected := tc.Analysis.Dependencies[i]
if got.Name != expected.Name || got.Version != expected.Version || got.Provider != expected.Provider {
t.Errorf("\nDifferent dependency error. Got %+v, expected %+v.\n\n", got, expected)
t.Errorf("\nDifferent dependency error. Got %+v\nExpected %+v.\n\n", got, expected)
}
}
}

// Check analysis-created Tags.
gotApp, _ := RichClient.Application.Get(tc.Application.ID)
for _, expected := range tc.AnalysisTags {
found := false
for _, got := range gotApp.Tags {
if got.Name == expected.Name && got.Source == "Analysis" {
found = true
break
}
}
if !found {
t.Errorf("Missing expected tag '%s'.\n", expected.Name)
}
}

if debug {
DumpTags(t, tc, *gotApp)
}

// TODO(maufart): analysis tagger creates duplicate tags, not sure if it is expected, check later.
//if len(tc.AnalysisTags) != len(gotApp.Tags) {
// t.Errorf("Different Tags amount error. Got: %d, expected: %d.\n", len(gotApp.Tags), len(tc.AnalysisTags))
//}
//found, gotAnalysisTags := 0, 0
//for _, t := range gotApp.Tags {
// if t.Source == "Analysis" {
// gotAnalysisTags = gotAnalysisTags + 1
// for _, expectedTag := range tc.AnalysisTags {
// if expectedTag.Name == t.Name {
// found = found + 1
// break
// }
// }
// }
//}
//if found != len(tc.AnalysisTags) || found < gotAnalysisTags {
// t.Errorf("Analysis Tags don't match. Got:\n %v\nexpected:\n %v\n", gotApp.Tags, tc.AnalysisTags)
//}
// Resolve TagRefs to Tags.
gotTags := []api.Tag{}
for _, tagRef := range gotApp.Tags {
if tagRef.Source == "Analysis" {
tag, _ := RichClient.Tag.Get(tagRef.ID)
gotTags = append(gotTags, *tag)
}
}

// Check Tags.
if len(tc.AnalysisTags) != len(gotApp.Tags) {
t.Errorf("Different Tags amount error. Got: %d, expected: %d.\n", len(gotApp.Tags), len(tc.AnalysisTags))
t.Errorf("Got: %+v\nExpected: %+v.\n", gotApp.Tags, tc.AnalysisTags)
} else {
for i, got := range gotTags {
expected := tc.AnalysisTags[i]
if got.Name != expected.Name || got.Category.Name != expected.Category.Name {
t.Errorf("\nDifferent tag error. Got %+v\nExpected %+v.\n\n", got, expected)
}
}
}

// Allow skip cleanup to keep applications and analysis results for debugging etc.
_, keep := os.LookupEnv("KEEP")
Expand Down
15 changes: 11 additions & 4 deletions analysis/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func DumpAnalysis(t *testing.T, tc TC, analysis api.Analysis) {
fmt.Printf(" },\n")
fmt.Printf(" },\n")
}
fmt.Printf(" },\n")
fmt.Printf(" Dependencies: []api.TechDependency{\n")
for _, dep := range analysis.Dependencies {
fmt.Printf(" {\n")
Expand All @@ -85,12 +86,18 @@ func DumpAnalysis(t *testing.T, tc TC, analysis api.Analysis) {
}

func DumpTags(t *testing.T, tc TC, app api.Application) {
// Preload tags.
tags := []api.Tag{}
for _, tagRef := range app.Tags {
if tagRef.Source == "Analysis" {
tag, _ := RichClient.Tag.Get(tagRef.ID)
tags = append(tags, *tag)
}
}
fmt.Printf("## GOT TAGS FOR \"%s\":", tc.Name)
fmt.Printf("\n[]api.Tag{\n")
for _, tag := range app.Tags {
if tag.Source == "Analysis" {
fmt.Printf(" {Name: \"%s\"},\n", tag.Name)
}
for _, tag := range tags {
fmt.Printf(" {Name: \"%s\", Category: api.Ref{Name: \"%s\")},\n", tag.Name, tag.Category.Name)
}
fmt.Printf("}\n")
}
24 changes: 12 additions & 12 deletions analysis/tc_tackle_testapp_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ var TackleTestappPublic = TC{
},
},
AnalysisTags: []api.Tag{
{Name: "EJB XML"},
{Name: "Servlet"},
{Name: "Properties"},
{Name: "Java EE Batch"},
{Name: "Java EE Batch"},
{Name: "Servlet"},
{Name: "EJB XML"},
{Name: "Properties"},
{Name: "Properties"},
{Name: "Java EE Batch"},
{Name: "EJB XML"},
{Name: "Servlet"},
{Name: "EJB XML", Category: api.Ref{Name: "Bean"}},
{Name: "Servlet", Category: api.Ref{Name: "HTTP"}},
{Name: "Properties", Category: api.Ref{Name: "Other"}},
{Name: "Java EE Batch", Category: api.Ref{Name: "Processing"}},
{Name: "Java EE Batch", Category: api.Ref{Name: "Java EE"}},
{Name: "Servlet", Category: api.Ref{Name: "Java EE"}},
{Name: "EJB XML", Category: api.Ref{Name: "Java EE"}},
{Name: "Properties", Category: api.Ref{Name: "Sustain"}},
{Name: "Properties", Category: api.Ref{Name: "Embedded"}},
{Name: "Java EE Batch", Category: api.Ref{Name: "Execute"}},
{Name: "EJB XML", Category: api.Ref{Name: "Connect"}},
{Name: "Servlet", Category: api.Ref{Name: "Connect"}},
},
}

0 comments on commit a9aad55

Please sign in to comment.