Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix private binary app analysis tier3 #114

Merged
merged 3 commits into from
Apr 17, 2024
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
45 changes: 14 additions & 31 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ 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.Error("Got:")
pp.Println(gotAnalysis.Issues)
t.Error("Expected:")
pp.Println(tc.Analysis.Issues)
missing, unexpected := getIssuesDiff(tc.Analysis.Issues, gotAnalysis.Issues)
for _, issue := range missing {
fmt.Printf("Expected issue not found for rule %s.\n", issue.Rule)
}
for _, issue := range unexpected {
fmt.Printf("Unexpected issue found for rule %s.\n", issue.Rule)
}
} else {
for i, got := range gotAnalysis.Issues {
expected := tc.Analysis.Issues[i]
Expand All @@ -208,10 +211,13 @@ 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.Error("Got:")
pp.Println(got.Incidents)
t.Error("Expected:")
pp.Println(expected.Incidents)
missing, unexpected := getIncidentsDiff(expected.Incidents, got.Incidents)
for _, incident := range missing {
fmt.Printf("Expected incident not found: %s line %d.\n", incident.File, incident.Line)
}
for _, incident := range unexpected {
fmt.Printf("Unexpected incident found: %s line %d.\n", incident.File, incident.Line)
}
aufi marked this conversation as resolved.
Show resolved Hide resolved

} else {
// Ensure stable order of Incidents.
Expand Down Expand Up @@ -348,26 +354,3 @@ func getDefaultToken() string {
}
return string(decrypted)
}

func getTagsDiff(want, got []api.Tag) (notFound []api.Tag, extras []api.Tag) {
tagKey := func(t api.Tag) string { return fmt.Sprintf("%s-%s", t.Category.Name, t.Name) }
wantTags := map[string]api.Tag{}
gotTags := map[string]api.Tag{}
for _, gotTag := range got {
gotTags[tagKey(gotTag)] = gotTag
}
for _, wantTag := range want {
wantTags[tagKey(wantTag)] = wantTag
// find tags we expect, but not present in output
if _, found := gotTags[tagKey(wantTag)]; !found {
notFound = append(notFound, wantTag)
}
}
for _, gotTag := range got {
// find tags we got, but we didn't expect
if _, found := wantTags[tagKey(gotTag)]; !found {
extras = append(extras, gotTag)
}
}
return
}
77 changes: 77 additions & 0 deletions analysis/compare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package analysis

import (
"fmt"

"github.com/konveyor/tackle2-hub/api"
)

// Compare diffs for resources collections relevant for Analysis
func getTagsDiff(want, got []api.Tag) (notFound []api.Tag, extras []api.Tag) {
tagKey := func(t api.Tag) string { return fmt.Sprintf("%s-%s", t.Category.Name, t.Name) }
wantTags := map[string]api.Tag{}
gotTags := map[string]api.Tag{}
for _, gotTag := range got {
gotTags[tagKey(gotTag)] = gotTag
}
for _, wantTag := range want {
wantTags[tagKey(wantTag)] = wantTag
// find tags we expect, but not present in output
if _, found := gotTags[tagKey(wantTag)]; !found {
notFound = append(notFound, wantTag)
}
}
for _, gotTag := range got {
// find tags we got, but we didn't expect
if _, found := wantTags[tagKey(gotTag)]; !found {
extras = append(extras, gotTag)
}
}
return
}

func getIssuesDiff(wantList, gotList []api.Issue) (notFound []api.Issue, extras []api.Issue) {
key := func(r api.Issue) string { return fmt.Sprintf("%s-%s-%s-%d", r.Category, r.RuleSet, r.Rule, r.Effort) }
wantMap := map[string]api.Issue{}
gotMap := map[string]api.Issue{}
for _, got := range gotList {
gotMap[key(got)] = got
}
for _, want := range wantList {
wantMap[key(want)] = want
// find what we expect, but not present in output
if _, found := gotMap[key(want)]; !found {
notFound = append(notFound, want)
}
}
for _, got := range gotList {
// find what we got, but we didn't expect
if _, found := wantMap[key(got)]; !found {
extras = append(extras, got)
}
}
return
}

func getIncidentsDiff(wantList, gotList []api.Incident) (notFound []api.Incident, extras []api.Incident) {
key := func(r api.Incident) string { return fmt.Sprintf("%s-%d", r.File, r.Line) }
wantMap := map[string]api.Incident{}
gotMap := map[string]api.Incident{}
for _, got := range gotList {
gotMap[key(got)] = got
}
for _, want := range wantList {
wantMap[key(want)] = want
// find tags we expect, but not present in output
if _, found := gotMap[key(want)]; !found {
notFound = append(notFound, want)
}
}
for _, got := range gotList {
// find tags we got, but we didn't expect
if _, found := wantMap[key(got)]; !found {
extras = append(extras, got)
}
}
return
}
25 changes: 10 additions & 15 deletions analysis/tc_tackle_testapp_private_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var TackleTestappPrivateBinary = TC{
},
Binary: true,
Analysis: api.Analysis{
Effort: 16,
Effort: 15,
Issues: []api.Issue{
{
Category: "mandatory",
Expand All @@ -31,7 +31,7 @@ var TackleTestappPrivateBinary = TC{
Rule: "jni-native-code-00000",
Incidents: []api.Incident{
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/config/ApplicationConfiguration.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/config/ApplicationConfiguration.java",
Line: 17,
Message: "\n Java native libraries might not run in a cloud or container environment.",
},
Expand All @@ -45,47 +45,42 @@ var TackleTestappPrivateBinary = TC{
Rule: "local-storage-00001",
Incidents: []api.Incident{
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/config/ApplicationConfiguration.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/config/ApplicationConfiguration.java",
Line: 8,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/config/ApplicationConfiguration.java",
Line: 37,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 39,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 40,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 41,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 42,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 61,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 62,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
{
File: "/addon/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/exception/handler/ExceptionHandlingController.java",
File: "/bin/maven/java-project/src/main/java/io/konveyor/demo/ordermanagement/exception/handler/ExceptionHandlingController.java",
Line: 20,
Message: "\n An application running inside a container could lose access to a file in local storage.",
},
Expand Down
Loading