Skip to content

Commit

Permalink
Merge pull request #24 from aufi/analysis-windup-reload
Browse files Browse the repository at this point in the history
Add windup analysis load
  • Loading branch information
aufi committed Sep 15, 2023
2 parents 86d0a0a + 7d08e04 commit 77a7ecb
Show file tree
Hide file tree
Showing 12 changed files with 869 additions and 122 deletions.
51 changes: 34 additions & 17 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package analysis

import (
"os"
"sort"
"strings"
"testing"
"time"

"github.com/konveyor/go-konveyor-tests/hack/addon"
"github.com/konveyor/go-konveyor-tests/hack/uniq"
"github.com/konveyor/go-konveyor-tests/hack/windupreport"
"github.com/konveyor/tackle2-hub/api"
"github.com/konveyor/tackle2-hub/binding"
"github.com/konveyor/tackle2-hub/test/assert"
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestApplicationAnalysis(t *testing.T) {
// Prepare and submit the analyze task.
// tc.Task.Addon = analyzerAddon
tc.Task.Application = &api.Ref{ID: tc.Application.ID}
taskData := tc.Task.Data.(addon.Data) // addon / addonwindup
taskData := tc.Task.Data.(addon.Data)
//for _, r := range tc.CustomRules {
// taskData.Rules = append(taskData.Rules, api.Ref{ID: r.ID, Name: r.Name})
//}
Expand All @@ -73,7 +73,10 @@ func TestApplicationAnalysis(t *testing.T) {
if len(tc.Targets) > 0 {
taskData.Targets = tc.Targets
}
if tc.Rules.Path != "" { // TODO: better rules handling
if len(tc.Labels.Included) > 0 || len(tc.Labels.Excluded) > 0 {
taskData.Rules.Labels = tc.Labels
}
if tc.Rules.Path != "" { // TODO: better rules handling
taskData.Rules = tc.Rules
}
tc.Task.Data = taskData
Expand All @@ -94,18 +97,18 @@ func TestApplicationAnalysis(t *testing.T) {
t.Errorf("Analyze Task failed. Details: %+v", task)
}

var gotAppAnalyses []api.Analysis
var gotAnalysis api.Analysis

if tc.Task.Addon == "windup" {
// Old Windup check version parsing windup HTML report
CheckWindupReportContent(t, &tc)
// Get LSP analysis directly form Hub API
analysisPath := binding.Path(api.AppAnalysesRoot).Inject(binding.Params{api.ID: tc.Application.ID})
assert.Should(t, Client.Get(analysisPath, &gotAppAnalyses))
analysisDetailPath := binding.Path(api.AnalysisRoot).Inject(binding.Params{api.ID: gotAppAnalyses[len(gotAppAnalyses)-1].ID})
assert.Should(t, Client.Get(analysisDetailPath, &gotAnalysis))

// Parse report for windup, to api.Analysis structure
gotAnalysis = windupreport.Parse(t, tc.Application.ID)
} else {
// Get LSP analysis directly form Hub API
analysisPath := binding.Path(api.AppAnalysisRoot).Inject(binding.Params{api.ID: tc.Application.ID})
assert.Should(t, Client.Get(analysisPath, &gotAnalysis))
_, debug := os.LookupEnv("DEBUG")
if debug {
DumpAnalysis(t, tc, gotAnalysis)
}

// Check the analysis result (effort, issues, etc).
Expand All @@ -117,6 +120,11 @@ func TestApplicationAnalysis(t *testing.T) {
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))
}

// Ensure stable order of Issues.
sort.SliceStable(gotAnalysis.Issues, func(a, b int) bool { return gotAnalysis.Issues[a].Rule < gotAnalysis.Issues[b].Rule })
sort.SliceStable(tc.Analysis.Issues, func(a, b int) bool { return tc.Analysis.Issues[a].Rule < tc.Analysis.Issues[b].Rule })

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) {
Expand All @@ -130,11 +138,15 @@ func TestApplicationAnalysis(t *testing.T) {
}
if len(got.Incidents) != len(expected.Incidents) {
t.Errorf("Different amount of incident error. Got %d, expected %d.", len(got.Incidents), len(expected.Incidents))
}
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)
} 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)
}
}
}
}
Expand All @@ -154,6 +166,11 @@ func TestApplicationAnalysis(t *testing.T) {
}
}

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))
Expand Down
12 changes: 4 additions & 8 deletions analysis/analyzer_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/konveyor/tackle2-hub/api"
)

var AnalyzeLsp = api.Task{
var Analyze = api.Task{
State: "Ready", // Created / Ready
Data: defaultAnalyzerData,
Addon: "analyzer",
Expand All @@ -17,7 +17,7 @@ var defaultAnalyzerData = addon.Data{
Artifact: "",
Binary: false,
WithDeps: false,
//Diva: true,
// Diva: true,
},
Sources: []string{},
Targets: []string{},
Expand All @@ -30,13 +30,10 @@ var defaultAnalyzerData = addon.Data{
},
Rules: addon.Rules{
Path: "",
Labels: struct {
Included []string `json:"included,omitempty"`
Excluded []string `json:"excluded,omitempty"`
}{
Labels: addon.Labels{
Excluded: []string{},
Included: []string{
"cloud-readiness",
"cloud-readiness",
},
},
//Tags: {
Expand All @@ -47,4 +44,3 @@ var defaultAnalyzerData = addon.Data{
Enabled: true,
},
}

57 changes: 49 additions & 8 deletions analysis/pkg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package analysis

import (
"fmt"
"testing"
"time"

"github.com/konveyor/go-konveyor-tests/hack/addon"
Expand Down Expand Up @@ -29,18 +31,57 @@ func init() {

// Test cases for Application Analysis.
type TC struct {
Name string
Name string
// Application and other test data declaration.
Application api.Application // Required.
CustomRules []api.RuleSet
Application api.Application // Required.
CustomRules []api.RuleSet
// Analysis parameters.
Task api.Task
TaskData string
Sources []string
Targets []string
Rules addon.Rules
Task api.Task
TaskData string
Sources []string
Targets []string
Labels addon.Labels
Rules addon.Rules
// After-analysis assertions.
ReportContent map[string][]string
Analysis api.Analysis
AnalysisTags []api.Tag
}

func DumpAnalysis(t *testing.T, tc TC, analysis api.Analysis) {
fmt.Printf("## GOT ANALYSIS OUTPUT FOR \"%s\":", tc.Name)
fmt.Printf("\napi.Analysis{\n")
fmt.Printf(" Effort: %d,\n", analysis.Effort)
fmt.Printf(" Issues: []api.Issue{\n")
for _, issue := range analysis.Issues {
fmt.Printf(" {\n")
fmt.Printf(" Category: \"%s\",\n", issue.Category)
fmt.Printf(" Description: \"%s\",\n", issue.Description)
fmt.Printf(" Effort: %d,\n", issue.Effort)
fmt.Printf(" RuleSet: \"%s\",\n", issue.RuleSet)
fmt.Printf(" Rule: \"%s\",\n", issue.Rule)
fmt.Printf(" Incidents: []api.Incident{\n")
for _, incident := range issue.Incidents {
fmt.Printf(" {\n")
fmt.Printf(" File: \"%s\",\n", incident.File)
fmt.Printf(" Line: %d,\n", incident.Line)
fmt.Printf(" Message: \"%s\",\n", incident.Message)
fmt.Printf(" },\n")
}
fmt.Printf(" },\n")
fmt.Printf(" },\n")
}
fmt.Printf(" },\n")
fmt.Printf("}\n")
}

func DumpTags(t *testing.T, tc TC, app api.Application) {
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)
}
}
fmt.Printf("}\n")
}
46 changes: 0 additions & 46 deletions analysis/tc_pathfinder_sample.go

This file was deleted.

108 changes: 108 additions & 0 deletions analysis/tc_tackle_testapp_public.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package analysis

import (
"github.com/konveyor/go-konveyor-tests/hack/addon"
"github.com/konveyor/tackle2-hub/api"
)

var TackleTestappPublic = TC{
Name: "Tackle Testapp public",
Application: api.Application{
Name: "Tackle Testapp public",
Repository: &api.Repository{
Kind: "git",
URL: "https://github.com/konveyor/tackle-testapp-public",
},
},
Task: Analyze,
Labels: addon.Labels{
Included: []string{
"konveyor.io/target=linux",
"konveyor.io/target=cloud-readiness",
},
},
Analysis: api.Analysis{
Effort: 10,
Issues: []api.Issue{
{
Category: "mandatory",
Description: "Hardcoded IP Address\nWhen migrating environments, hard-coded IP addresses may need to be modified or eliminated.",
Effort: 1,
RuleSet: "discovery-rules",
Rule: "hardcoded-ip-address",
Incidents: []api.Incident{
{
File: "/addon/source/tackle-testapp-public/target/classes/persistence.properties",
Line: 0,
Message: "When migrating environments, hard-coded IP addresses may need to be modified or eliminated.",
},
{
File: "/addon/source/tackle-testapp-public/src/main/resources/persistence.properties",
Line: 0,
Message: "When migrating environments, hard-coded IP addresses may need to be modified or eliminated.",
},
},
},
{
Category: "mandatory",
Description: "File system - Java IO\nAn application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
Effort: 1,
RuleSet: "openshift",
Rule: "local-storage-00001",
Incidents: []api.Incident{
{
File: "/addon/source/tackle-testapp-public/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 0,
Message: "An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
},
{
File: "/addon/source/tackle-testapp-public/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 0,
Message: "An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
},
{
File: "/addon/source/tackle-testapp-public/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 0,
Message: "An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
},
{
File: "/addon/source/tackle-testapp-public/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 0,
Message: "An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
},
{
File: "/addon/source/tackle-testapp-public/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 0,
Message: "An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
},
{
File: "/addon/source/tackle-testapp-public/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 0,
Message: "An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
},
{
File: "/addon/source/tackle-testapp-public/src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.java",
Line: 0,
Message: "An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.",
},
},
},
{
Category: "mandatory",
Description: "Windows file system path\nThis file system path is Microsoft Windows platform dependent. It needs to be replaced with a Linux-style path.",
Effort: 1,
RuleSet: "os/windows",
Rule: "os-specific-00001",
Incidents: []api.Incident{
{
File: "/addon/source/tackle-testapp-public/.git/hooks/fsmonitor-watchman.sample",
Line: 0,
Message: "This file system path is Microsoft Windows platform dependent. It needs to be replaced with a Linux-style path.",
},
},
},
},
},
// Tags are empty right now.
AnalysisTags: []api.Tag{},
}
Loading

0 comments on commit 77a7ecb

Please sign in to comment.