diff --git a/test/api/importcsv/api_test.go b/test/api/importcsv/api_test.go index a82a2146..19a75bb8 100644 --- a/test/api/importcsv/api_test.go +++ b/test/api/importcsv/api_test.go @@ -1,6 +1,7 @@ package importcsv import ( + "fmt" "strconv" "testing" @@ -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()) } @@ -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{} @@ -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") + } }) } } diff --git a/test/api/importcsv/pkg.go b/test/api/importcsv/pkg.go index e10c7345..86dd7663 100644 --- a/test/api/importcsv/pkg.go +++ b/test/api/importcsv/pkg.go @@ -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 diff --git a/test/api/importcsv/samples.go b/test/api/importcsv/samples.go index a6d4a2bc..f89deaab 100644 --- a/test/api/importcsv/samples.go +++ b/test/api/importcsv/samples.go @@ -5,7 +5,7 @@ import ( ) type TestCase struct { - fileName string + FileName string ExpectedApplications []api.Application ExpectedDependencies []api.Dependency } @@ -13,7 +13,7 @@ type TestCase struct { var ( TestCases = []TestCase{ { - fileName: "template_application_import.csv", + FileName: "template_application_import.csv", ExpectedApplications: []api.Application{ { Name: "Customers",