Skip to content

Commit

Permalink
Upload binary analysis test (#101)
Browse files Browse the repository at this point in the history
Signed-off-by: Maayan Hadasi <mguetta@redhat.com>
  • Loading branch information
mguetta1 committed Mar 19, 2024
1 parent b70d8e0 commit f2eaffd
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 2 deletions.
36 changes: 36 additions & 0 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"crypto/cipher"
"crypto/sha256"
"encoding/hex"
"io"
"net/http"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -116,9 +118,20 @@ func TestApplicationAnalysis(t *testing.T) {
if tc.Scope != nil {
taskData.Scope = *tc.Scope
}

taskData.Mode.Artifact = tc.Artifact
tc.Task.Data = taskData
assert.Should(t, RichClient.Task.Create(&tc.Task))

if tc.Artifact != "" {
// Upload binary file into the bucket
bucketContent := RichClient.Bucket.Content(tc.Task.Bucket.ID)
bucketContent.Put("data"+tc.Artifact, tc.Artifact)
}

tc.Task.State = "Ready"
assert.Should(t, RichClient.Task.Update(&tc.Task))

// Wait until task finishes
var task *api.Task
var err error
Expand Down Expand Up @@ -328,3 +341,26 @@ func getDefaultToken() string {
}
return string(decrypted)
}

// DownloadFile downloads the file, params:
// 1) name of file to save as
// 2) URL to download FROM
func DownloadFile(filePath string, url string) error {
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

// Create the file
out, err := os.Create(filePath)
if err != nil {
return err
}
defer out.Close()

// Write the body to file
_, err = io.Copy(out, resp.Body)
return err
}
2 changes: 1 addition & 1 deletion analysis/analyzer_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var Analyze = api.Task{
State: "Ready", // Created / Ready
State: "Created", // Created / Ready
Data: defaultAnalyzerData,
Addon: "analyzer",
}
Expand Down
Binary file added analysis/data/binary/administracion_efectivo.ear
Binary file not shown.
1 change: 1 addition & 0 deletions analysis/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type TC struct {
Scope *addon.Scope
WithDeps bool
Binary bool
Artifact string
// After-analysis assertions.
ReportContent map[string][]string
Analysis api.Analysis
Expand Down
63 changes: 63 additions & 0 deletions analysis/tc_administracion_efectivo_upload_binary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package analysis

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

var AdministracionEfectivo = TC{
Name: "administracion-efectivo",
Application: data.UploadBinary,
Task: Analyze,
Labels: addon.Labels{
Included: []string{
"konveyor.io/target=cloud-readiness",
},
},
Binary: true,
Artifact: "/binary/administracion_efectivo.ear",
Analysis: api.Analysis{
Effort: 1591,
Issues: []api.Issue{
{
Category: "mandatory",
Description: "Java native libraries (JNI, JNA)",
Effort: 7,
RuleSet: "cloud-readiness",
Rule: "jni-native-code-00000",
},
{
Category: "mandatory",
Description: "File system - Java IO",
Effort: 1,
RuleSet: "cloud-readiness",
Rule: "local-storage-00001",
},
{
Category: "mandatory",
Description: "File system - java.net.URL/URI",
Effort: 1,
RuleSet: "cloud-readiness",
Rule: "local-storage-00002",
},
},
},
AnalysisTags: []api.Tag{
{Name: "Servlet", Category: api.Ref{Name: "HTTP"}},
{Name: "EAR Deployment", Category: api.Ref{Name: "Other"}},
{Name: "JNI", Category: api.Ref{Name: "Other"}},
{Name: "Mail", Category: api.Ref{Name: "Other"}},
{Name: "Spring Scheduled", Category: api.Ref{Name: "Processing"}},
{Name: "Mail", Category: api.Ref{Name: "Connect"}},
{Name: "Servlet", Category: api.Ref{Name: "Connect"}},
{Name: "EAR Deployment", Category: api.Ref{Name: "Connect"}},
{Name: "JNI", Category: api.Ref{Name: "Connect"}},
{Name: "JNI", Category: api.Ref{Name: "Java EE"}},
{Name: "Servlet", Category: api.Ref{Name: "Java EE"}},
{Name: "EAR Deployment", Category: api.Ref{Name: "Java EE"}},
{Name: "Mail", Category: api.Ref{Name: "Java EE"}},
{Name: "Spring Scheduled", Category: api.Ref{Name: "Embedded"}},
{Name: "Spring Scheduled", Category: api.Ref{Name: "Execute"}},
},
}
File renamed without changes.
1 change: 1 addition & 0 deletions analysis/test_cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package analysis
var Tier0TestCases = []TC{
TackleTestappPublicWithDeps,
TackleTestappPublicPackageFilter,
AdministracionEfectivo,
}

// Tier 1 Analysis test cases - should work.
Expand Down
5 changes: 4 additions & 1 deletion data/application_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ var (
},
Binary: "io.konveyor.demo:customers-tomcat:0.0.1-SNAPSHOT:war",
}
ApplicationSamples = []api.Application{Minimal, PathfinderGit, BookServer, TackleTestapp}
UploadBinary = api.Application {
Name: "upload-binary",
}
ApplicationSamples = []api.Application{Minimal, PathfinderGit, BookServer, TackleTestapp, UploadBinary}
)

0 comments on commit f2eaffd

Please sign in to comment.