Skip to content

Commit

Permalink
added valid count check
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Khare <yash2010118@akgec.ac.in>
  • Loading branch information
khareyash05 committed Jun 24, 2023
1 parent e3a116f commit 606abcd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
47 changes: 31 additions & 16 deletions test/api/importcsv/api_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package importcsv

import (
"fmt"
"strconv"
"testing"

Expand All @@ -9,11 +10,11 @@ import (

func TestImportCSV(t *testing.T) {
for _, r := range TestCases {
t.Run(r.fileName, func(t *testing.T) {
t.Run(r.FileName, func(t *testing.T) {

// Upload CSV.
inputData := make(map[string]interface{})
err := Client.FilePost("/importsummaries/upload", r.fileName, &inputData)
err := Client.FilePost("/importsummaries/upload", r.FileName, &inputData)
if err != nil {
t.Errorf(err.Error())
}
Expand Down Expand Up @@ -46,23 +47,25 @@ func TestImportCSV(t *testing.T) {
}
}

// fetch id's
// fetch id of CSV file and convert it into required formats
id := uint64(inputData["id"].(float64))
var inputID = strconv.FormatUint(id, 10)
var output []api.ImportSummary
err = Client.Get("/importsummaries/", &output)
var inputID = strconv.FormatUint(id, 10) // to be used for API compatibility

var outputImportSummaries []api.ImportSummary
outputMatchingSummary := api.ImportSummary{}
err = Client.Get("/importsummaries", &outputImportSummaries)
if err != nil {
t.Errorf("Can't get summaries of all imports")
t.Errorf("failed to get import summary: %v", err)
}
for _, imp := range outputImportSummaries {
if uint64(imp.ID) == id {
outputMatchingSummary = imp
}
}
fmt.Println(outputMatchingSummary)
if len(importedDeps)+len(importedApps) != outputMatchingSummary.ValidCount {
t.Errorf("valid count not matching with number of applications and dependencies")
}

// check for the id and return valid
// for _, imp := range output {
// if uint64(imp.ID) == id {
// if len(importedDeps)+len(importedApps) != imp.ValidCount {
// t.Errorf("Mismatch in number of valid count")
// }
// }
// }

// Get summaries of the Input ID.
outputImport := api.ImportSummary{}
Expand All @@ -76,6 +79,18 @@ func TestImportCSV(t *testing.T) {
if err != nil {
t.Errorf("CSV delete failed")
}

// Delete related Applications.
err = Application.Delete(uint(id))
if err != nil {
t.Errorf("Application delete failed")
}

// Delete related Dependencies.
err = Dependency.Delete(uint(id))
if err != nil {
t.Errorf("Dependency delete failed")
}
})
}
}
2 changes: 1 addition & 1 deletion test/api/importcsv/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
RichClient = client.PrepareRichClient()

// Access REST client directly
Client = RichClient.Client()
Client = RichClient.Client

// Access Application directly
Application = RichClient.Application
Expand Down
4 changes: 2 additions & 2 deletions test/api/importcsv/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
)

type TestCase struct {
fileName string
FileName string
ExpectedApplications []api.Application
ExpectedDependencies []api.Dependency
}

var (
TestCases = []TestCase{
{
fileName: "template_application_import.csv",
FileName: "template_application_import.csv",
ExpectedApplications: []api.Application{
{
Name: "Customers",
Expand Down

0 comments on commit 606abcd

Please sign in to comment.