From 87d9dd6a993a426ad0c506852b87170844613617 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Tue, 8 Aug 2023 12:10:49 +0530 Subject: [PATCH 1/7] :seedling: add migrationwave API test Signed-off-by: Yash Khare --- api/ruleset.go | 2 +- binding/migrationwave.go | 50 ++++++++++++++++++++ binding/richclient.go | 4 ++ test/api/migrationwave/api_test.go | 75 ++++++++++++++++++++++++++++++ test/api/migrationwave/pkg.go | 31 ++++++++++++ test/api/migrationwave/samples.go | 33 +++++++++++++ 6 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 binding/migrationwave.go create mode 100644 test/api/migrationwave/api_test.go create mode 100644 test/api/migrationwave/pkg.go create mode 100644 test/api/migrationwave/samples.go diff --git a/api/ruleset.go b/api/ruleset.go index c270171da..9b390f95b 100644 --- a/api/ruleset.go +++ b/api/ruleset.go @@ -121,7 +121,7 @@ func (h RuleSetHandler) Create(ctx *gin.Context) { _ = ctx.Error(err) return } - + h.Respond(ctx, http.StatusCreated, ruleset) } diff --git a/binding/migrationwave.go b/binding/migrationwave.go new file mode 100644 index 000000000..3a1d555bf --- /dev/null +++ b/binding/migrationwave.go @@ -0,0 +1,50 @@ +package binding + +import ( + "github.com/konveyor/tackle2-hub/api" +) + +// +// MigrationWave API. +type MigrationWave struct { + client *Client +} + +// +// Create a MigrationWave. +func (h *MigrationWave) Create(r *api.MigrationWave) (err error) { + err = h.client.Post(api.MigrationWavesRoot, &r) + return +} + +// +// Get a MigrationWave by ID. +func (h *MigrationWave) Get(id uint) (r *api.MigrationWave, err error) { + r = &api.MigrationWave{} + path := Path(api.MigrationWaveRoot).Inject(Params{api.ID: id}) + err = h.client.Get(path, r) + return +} + +// +// List Reviews. +func (h *MigrationWave) List() (list []api.MigrationWave, err error) { + list = []api.MigrationWave{} + err = h.client.Get(api.MigrationWavesRoot, &list) + return +} + +// +// Update a MigrationWave. +func (h *MigrationWave) Update(r *api.MigrationWave) (err error) { + path := Path(api.MigrationWaveRoot).Inject(Params{api.ID: r.ID}) + err = h.client.Put(path, r) + return +} + +// +// Delete a MigrationWave. +func (h *MigrationWave) Delete(id uint) (err error) { + err = h.client.Delete(Path(api.MigrationWaveRoot).Inject(Params{api.ID: id})) + return +} diff --git a/binding/richclient.go b/binding/richclient.go index 3896870fd..56516580d 100644 --- a/binding/richclient.go +++ b/binding/richclient.go @@ -27,6 +27,7 @@ type RichClient struct { File File Identity Identity JobFunction JobFunction + MigrationWave MigrationWave Proxy Proxy Review Review RuleSet RuleSet @@ -73,6 +74,9 @@ func New(baseUrl string) (r *RichClient) { JobFunction: JobFunction{ client: client, }, + MigrationWave: MigrationWave{ + client: client, + }, Proxy: Proxy{ client: client, }, diff --git a/test/api/migrationwave/api_test.go b/test/api/migrationwave/api_test.go new file mode 100644 index 000000000..0d13521b4 --- /dev/null +++ b/test/api/migrationwave/api_test.go @@ -0,0 +1,75 @@ +package migrationwave + +import ( + "testing" + "time" + + "github.com/konveyor/tackle2-hub/api" + "github.com/konveyor/tackle2-hub/test/assert" +) + +func TestReviewCRUD(t *testing.T) { + for _, r := range Samples { + expectedApp := api.Application{ + Name: "Sample Application", + Description: "Sample application", + } + assert.Must(t, Application.Create(&expectedApp)) + + expectedStakeholder := api.Stakeholder{ + Name: "Sample Stakeholder", + Email: "sample@example.com", + } + assert.Must(t, Stakeholder.Create(&expectedStakeholder)) + + expectedStakeholderGroup := api.StakeholderGroup{ + Name: "Sample Stakeholder Group", + } + assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) + + assert.Must(t, MigrationWave.Create(&r)) + + // Get migration wave. + got, err := MigrationWave.Get(r.ID) + if err != nil { + t.Errorf(err.Error()) + } + + // Compare got values with expected values. + AssertEqualMigrationWaves(t, got, r) + + // Update MigrationWave's Name. + r.EndDate = r.EndDate.Add(30 * time.Minute) + assert.Should(t, MigrationWave.Update(&r)) + + // Find MigrationWave and check its parameters with the got(On Updation). + got, err = MigrationWave.Get(r.ID) + if err != nil { + t.Errorf(err.Error()) + } + + // Check if the unchanged values remain same or not. + AssertEqualMigrationWaves(t, got, r) + + // Delete created Applications, Stakeholders,StakeholdersGroup and MigrationWave + assert.Must(t, Application.Delete(expectedApp.ID)) + assert.Must(t, Stakeholder.Delete(expectedStakeholder.ID)) + assert.Must(t, StakeholderGroup.Delete(expectedStakeholderGroup.ID)) + assert.Must(t, MigrationWave.Delete(r.ID)) + + // Check if the MigrationWave is present even after deletion or not. + _, err = MigrationWave.Get(r.ID) + if err == nil { + t.Errorf("Resource exits, but should be deleted: %v", r) + } + } +} + +func AssertEqualMigrationWaves(t *testing.T, got *api.MigrationWave, expected api.MigrationWave) { + if got.Name != expected.Name { + t.Errorf("Different MigrationWave Name Got %v, expected %v", got.Name, expected.Name) + } + if got.StartDate != expected.StartDate { + t.Errorf("Different Start Date Got %v, expected %v", got.StartDate, expected.StartDate) + } +} diff --git a/test/api/migrationwave/pkg.go b/test/api/migrationwave/pkg.go new file mode 100644 index 000000000..429f6ff03 --- /dev/null +++ b/test/api/migrationwave/pkg.go @@ -0,0 +1,31 @@ +package migrationwave + +import ( + "github.com/konveyor/tackle2-hub/binding" + "github.com/konveyor/tackle2-hub/test/api/client" +) + +var ( + RichClient *binding.RichClient + MigrationWave binding.MigrationWave + Application binding.Application + Stakeholder binding.Stakeholder + StakeholderGroup binding.StakeholderGroup +) + +func init() { + // Prepare RichClient and login to Hub API (configured from env variables). + RichClient = client.PrepareRichClient() + + // Shortcut for MigrationWave-related RichClient methods. + MigrationWave = RichClient.MigrationWave + + // Shortcut for Application-related RichClient methods. + Application = RichClient.Application + + // Shortcut for StakeHolder-related RichClient methods. + Stakeholder = RichClient.Stakeholder + + // Shortcut for StakeHolderGroup-related RichClient methods. + StakeholderGroup = RichClient.StakeholderGroup +} diff --git a/test/api/migrationwave/samples.go b/test/api/migrationwave/samples.go new file mode 100644 index 000000000..99fe2fdad --- /dev/null +++ b/test/api/migrationwave/samples.go @@ -0,0 +1,33 @@ +package migrationwave + +import ( + "time" + + "github.com/konveyor/tackle2-hub/api" +) + +var Samples = []api.MigrationWave{ + { + Name: "MigrationWaves", + StartDate: time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local), + EndDate: time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local).Add(30 * time.Minute), + Applications: []api.Ref{ + { + ID: 1, + Name: "Sample Application", + }, + }, + Stakeholders: []api.Ref{ + { + ID: 2, + Name: "Sample Stakeholders", + }, + }, + StakeholderGroups: []api.Ref{ + { + ID: 3, + Name: "Sample Stakeholders Groups", + }, + }, + }, +} From f15ef5f5c0033dd58fe50ac832d3feb99f7485bd Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Tue, 8 Aug 2023 12:30:55 +0530 Subject: [PATCH 2/7] update tests to add MigrationWave.List() Signed-off-by: Yash Khare --- test/api/migrationwave/api_test.go | 110 +++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 14 deletions(-) diff --git a/test/api/migrationwave/api_test.go b/test/api/migrationwave/api_test.go index 0d13521b4..d9e4d5d81 100644 --- a/test/api/migrationwave/api_test.go +++ b/test/api/migrationwave/api_test.go @@ -10,22 +10,29 @@ import ( func TestReviewCRUD(t *testing.T) { for _, r := range Samples { - expectedApp := api.Application{ - Name: "Sample Application", - Description: "Sample application", + for _, app := range r.Applications { + expectedApp := api.Application{ + Name: app.Name, + Description: "Sample application", + } + assert.Must(t, Application.Create(&expectedApp)) } - assert.Must(t, Application.Create(&expectedApp)) - expectedStakeholder := api.Stakeholder{ - Name: "Sample Stakeholder", - Email: "sample@example.com", + for _, stakeholder := range r.Stakeholders { + expectedStakeholder := api.Stakeholder{ + Name: stakeholder.Name, + Email: "sample@example.com", + } + assert.Must(t, Stakeholder.Create(&expectedStakeholder)) } - assert.Must(t, Stakeholder.Create(&expectedStakeholder)) - expectedStakeholderGroup := api.StakeholderGroup{ - Name: "Sample Stakeholder Group", + for _, stakeholderGroup := range r.StakeholderGroups { + expectedStakeholderGroup := api.StakeholderGroup{ + Name: stakeholderGroup.Name, + Description: "Sample Stakeholder Group", + } + assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) } - assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) assert.Must(t, MigrationWave.Create(&r)) @@ -52,9 +59,15 @@ func TestReviewCRUD(t *testing.T) { AssertEqualMigrationWaves(t, got, r) // Delete created Applications, Stakeholders,StakeholdersGroup and MigrationWave - assert.Must(t, Application.Delete(expectedApp.ID)) - assert.Must(t, Stakeholder.Delete(expectedStakeholder.ID)) - assert.Must(t, StakeholderGroup.Delete(expectedStakeholderGroup.ID)) + for _, app := range r.Applications { + assert.Must(t, Application.Delete(app.ID)) + } + for _, stakeholder := range r.Stakeholders { + assert.Must(t, Stakeholder.Delete(stakeholder.ID)) + } + for _, stakeholderGroup := range r.StakeholderGroups { + assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) + } assert.Must(t, MigrationWave.Delete(r.ID)) // Check if the MigrationWave is present even after deletion or not. @@ -65,6 +78,75 @@ func TestReviewCRUD(t *testing.T) { } } +func TestMigrationWaveList(t *testing.T) { + createdMigrationWaves := []api.MigrationWave{} + + for _, r := range Samples { + for _, app := range r.Applications { + expectedApp := api.Application{ + Name: app.Name, + Description: "Sample application", + } + assert.Must(t, Application.Create(&expectedApp)) + } + + for _, stakeholder := range r.Stakeholders { + expectedStakeholder := api.Stakeholder{ + Name: stakeholder.Name, + Email: "sample@example.com", + } + assert.Must(t, Stakeholder.Create(&expectedStakeholder)) + } + + for _, stakeholderGroup := range r.StakeholderGroups { + expectedStakeholderGroup := api.StakeholderGroup{ + Name: stakeholderGroup.Name, + Description: "Sample Stakeholder Group", + } + assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) + } + + assert.Must(t, MigrationWave.Create(&r)) + createdMigrationWaves = append(createdMigrationWaves, r) + } + + // List MigrationWaves. + got, err := MigrationWave.List() + if err != nil { + t.Errorf(err.Error()) + } + + // Compare contents of migration waves. + for _, createdMigrationWave := range createdMigrationWaves { + found := false + for _, retrievedReview := range got { + if assert.FlatEqual(createdMigrationWave.ID, retrievedReview.ID) { + found = true + break + } + } + if !found { + t.Errorf("Expected review not found in the list: %v", createdMigrationWave) + } + } + + // Delete created resources. + for _, createdMigrationWave := range createdMigrationWaves { + for _, app := range createdMigrationWave.Applications { + assert.Must(t, Application.Delete(app.ID)) + } + + for _, stakeholder := range createdMigrationWave.Stakeholders { + assert.Must(t, Stakeholder.Delete(stakeholder.ID)) + } + + for _, stakeholderGroup := range createdMigrationWave.StakeholderGroups { + assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) + } + assert.Must(t, MigrationWave.Delete(createdMigrationWave.ID)) + } +} + func AssertEqualMigrationWaves(t *testing.T, got *api.MigrationWave, expected api.MigrationWave) { if got.Name != expected.Name { t.Errorf("Different MigrationWave Name Got %v, expected %v", got.Name, expected.Name) From 33b8ce8591c1687fa536aef86752c74c931cd12d Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Tue, 8 Aug 2023 12:35:35 +0530 Subject: [PATCH 3/7] updated code Signed-off-by: Yash Khare --- test/api/migrationwave/api_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/api/migrationwave/api_test.go b/test/api/migrationwave/api_test.go index d9e4d5d81..ea5554311 100644 --- a/test/api/migrationwave/api_test.go +++ b/test/api/migrationwave/api_test.go @@ -1,6 +1,7 @@ package migrationwave import ( + "strconv" "testing" "time" @@ -93,19 +94,18 @@ func TestMigrationWaveList(t *testing.T) { for _, stakeholder := range r.Stakeholders { expectedStakeholder := api.Stakeholder{ Name: stakeholder.Name, - Email: "sample@example.com", + Email: "sample1@example.com", } assert.Must(t, Stakeholder.Create(&expectedStakeholder)) } - for _, stakeholderGroup := range r.StakeholderGroups { + for i, stakeholderGroup := range r.StakeholderGroups { expectedStakeholderGroup := api.StakeholderGroup{ - Name: stakeholderGroup.Name, + Name: stakeholderGroup.Name + strconv.Itoa(i), Description: "Sample Stakeholder Group", } assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) } - assert.Must(t, MigrationWave.Create(&r)) createdMigrationWaves = append(createdMigrationWaves, r) } From 46eda23e4342f7327b30a43fe9e5559e9de578bd Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Thu, 10 Aug 2023 08:35:32 +0530 Subject: [PATCH 4/7] fix typos Signed-off-by: Yash Khare --- binding/migrationwave.go | 2 +- test/api/migrationwave/api_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/binding/migrationwave.go b/binding/migrationwave.go index 3a1d555bf..abacc3711 100644 --- a/binding/migrationwave.go +++ b/binding/migrationwave.go @@ -27,7 +27,7 @@ func (h *MigrationWave) Get(id uint) (r *api.MigrationWave, err error) { } // -// List Reviews. +// List MigrationWaves. func (h *MigrationWave) List() (list []api.MigrationWave, err error) { list = []api.MigrationWave{} err = h.client.Get(api.MigrationWavesRoot, &list) diff --git a/test/api/migrationwave/api_test.go b/test/api/migrationwave/api_test.go index ea5554311..8f5170d8f 100644 --- a/test/api/migrationwave/api_test.go +++ b/test/api/migrationwave/api_test.go @@ -9,7 +9,7 @@ import ( "github.com/konveyor/tackle2-hub/test/assert" ) -func TestReviewCRUD(t *testing.T) { +func TestMigrationWaveCRUD(t *testing.T) { for _, r := range Samples { for _, app := range r.Applications { expectedApp := api.Application{ @@ -117,16 +117,16 @@ func TestMigrationWaveList(t *testing.T) { } // Compare contents of migration waves. - for _, createdMigrationWave := range createdMigrationWaves { + for _, createdWave := range createdMigrationWaves { found := false - for _, retrievedReview := range got { - if assert.FlatEqual(createdMigrationWave.ID, retrievedReview.ID) { + for _, retrievedWave := range got { + if assert.FlatEqual(createdWave.ID, retrievedWave.ID) { found = true break } } if !found { - t.Errorf("Expected review not found in the list: %v", createdMigrationWave) + t.Errorf("Expected Wave not found in the list: %v", createdWave) } } From 0f426e27787366523e4a812474d931c7ebf84912 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Tue, 15 Aug 2023 20:01:07 +0530 Subject: [PATCH 5/7] updated check migrationwave function Signed-off-by: Yash Khare --- test/api/migrationwave/api_test.go | 60 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/test/api/migrationwave/api_test.go b/test/api/migrationwave/api_test.go index 8f5170d8f..5ffa21aff 100644 --- a/test/api/migrationwave/api_test.go +++ b/test/api/migrationwave/api_test.go @@ -60,16 +60,19 @@ func TestMigrationWaveCRUD(t *testing.T) { AssertEqualMigrationWaves(t, got, r) // Delete created Applications, Stakeholders,StakeholdersGroup and MigrationWave - for _, app := range r.Applications { - assert.Must(t, Application.Delete(app.ID)) + assert.Must(t, MigrationWave.Delete(r.ID)) + + for _, stakeholderGroup := range r.StakeholderGroups { + assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) } + for _, stakeholder := range r.Stakeholders { assert.Must(t, Stakeholder.Delete(stakeholder.ID)) } - for _, stakeholderGroup := range r.StakeholderGroups { - assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) + + for _, app := range r.Applications { + assert.Must(t, Application.Delete(app.ID)) } - assert.Must(t, MigrationWave.Delete(r.ID)) // Check if the MigrationWave is present even after deletion or not. _, err = MigrationWave.Get(r.ID) @@ -132,18 +135,19 @@ func TestMigrationWaveList(t *testing.T) { // Delete created resources. for _, createdMigrationWave := range createdMigrationWaves { - for _, app := range createdMigrationWave.Applications { - assert.Must(t, Application.Delete(app.ID)) + assert.Must(t, MigrationWave.Delete(createdMigrationWave.ID)) + + for _, stakeholderGroup := range createdMigrationWave.StakeholderGroups { + assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) } for _, stakeholder := range createdMigrationWave.Stakeholders { assert.Must(t, Stakeholder.Delete(stakeholder.ID)) } - for _, stakeholderGroup := range createdMigrationWave.StakeholderGroups { - assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) + for _, app := range createdMigrationWave.Applications { + assert.Must(t, Application.Delete(app.ID)) } - assert.Must(t, MigrationWave.Delete(createdMigrationWave.ID)) } } @@ -154,4 +158,40 @@ func AssertEqualMigrationWaves(t *testing.T, got *api.MigrationWave, expected ap if got.StartDate != expected.StartDate { t.Errorf("Different Start Date Got %v, expected %v", got.StartDate, expected.StartDate) } + for _, expectedApp := range expected.Applications { + found := false + for _, gotApp := range got.Applications { + if assert.FlatEqual(expectedApp.ID, gotApp.ID) { + found = true + break + } + } + if !found { + t.Errorf("Expected Wave not found in the list: %v", expectedApp) + } + } + for _, expectedStakeholders := range expected.Stakeholders { + found := false + for _, gotStakeholders := range got.Stakeholders { + if assert.FlatEqual(expectedStakeholders.ID, gotStakeholders.ID) { + found = true + break + } + } + if !found { + t.Errorf("Expected Wave not found in the list: %v", expectedStakeholders) + } + } + for _, expectedStakeholderGroup := range expected.StakeholderGroups { + found := false + for _, gotStakeholderGroup := range got.StakeholderGroups { + if assert.FlatEqual(expectedStakeholderGroup.ID, gotStakeholderGroup.ID) { + found = true + break + } + } + if !found { + t.Errorf("Expected Wave not found in the list: %v", expectedStakeholderGroup) + } + } } From bf4ab5eebd7706d46c8bc87363f9033eca0c5c8e Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 16 Aug 2023 15:49:13 +0530 Subject: [PATCH 6/7] update test and docs Signed-off-by: Yash Khare --- docs/test-api-matrix.md | 2 +- test/api/migrationwave/api_test.go | 61 ++++-------------------------- test/api/migrationwave/samples.go | 3 -- 3 files changed, 8 insertions(+), 58 deletions(-) diff --git a/docs/test-api-matrix.md b/docs/test-api-matrix.md index 052f0d4c2..2391f2bff 100644 --- a/docs/test-api-matrix.md +++ b/docs/test-api-matrix.md @@ -24,7 +24,7 @@ analysis|||| ruleset|:heavy_check_mark:|:heavy_check_mark:|| **Migrationwaves and Jira**|||| batch|||| -migrationwave|||| +migrationwave|:heavy_check_mark:|:heavy_check_mark:|| ticket|||| tracker|||| **Other**|||| diff --git a/test/api/migrationwave/api_test.go b/test/api/migrationwave/api_test.go index 5ffa21aff..5cfbac367 100644 --- a/test/api/migrationwave/api_test.go +++ b/test/api/migrationwave/api_test.go @@ -1,7 +1,6 @@ package migrationwave import ( - "strconv" "testing" "time" @@ -11,29 +10,6 @@ import ( func TestMigrationWaveCRUD(t *testing.T) { for _, r := range Samples { - for _, app := range r.Applications { - expectedApp := api.Application{ - Name: app.Name, - Description: "Sample application", - } - assert.Must(t, Application.Create(&expectedApp)) - } - - for _, stakeholder := range r.Stakeholders { - expectedStakeholder := api.Stakeholder{ - Name: stakeholder.Name, - Email: "sample@example.com", - } - assert.Must(t, Stakeholder.Create(&expectedStakeholder)) - } - - for _, stakeholderGroup := range r.StakeholderGroups { - expectedStakeholderGroup := api.StakeholderGroup{ - Name: stakeholderGroup.Name, - Description: "Sample Stakeholder Group", - } - assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) - } assert.Must(t, MigrationWave.Create(&r)) @@ -83,32 +59,9 @@ func TestMigrationWaveCRUD(t *testing.T) { } func TestMigrationWaveList(t *testing.T) { - createdMigrationWaves := []api.MigrationWave{} + createdMigrationWaves := []api.MigrationWave{} for _, r := range Samples { - for _, app := range r.Applications { - expectedApp := api.Application{ - Name: app.Name, - Description: "Sample application", - } - assert.Must(t, Application.Create(&expectedApp)) - } - - for _, stakeholder := range r.Stakeholders { - expectedStakeholder := api.Stakeholder{ - Name: stakeholder.Name, - Email: "sample1@example.com", - } - assert.Must(t, Stakeholder.Create(&expectedStakeholder)) - } - - for i, stakeholderGroup := range r.StakeholderGroups { - expectedStakeholderGroup := api.StakeholderGroup{ - Name: stakeholderGroup.Name + strconv.Itoa(i), - Description: "Sample Stakeholder Group", - } - assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) - } assert.Must(t, MigrationWave.Create(&r)) createdMigrationWaves = append(createdMigrationWaves, r) } @@ -133,19 +86,19 @@ func TestMigrationWaveList(t *testing.T) { } } - // Delete created resources. - for _, createdMigrationWave := range createdMigrationWaves { - assert.Must(t, MigrationWave.Delete(createdMigrationWave.ID)) + for _, r := range createdMigrationWaves { + // Delete created Applications, Stakeholders,StakeholdersGroup and MigrationWave + assert.Must(t, MigrationWave.Delete(r.ID)) - for _, stakeholderGroup := range createdMigrationWave.StakeholderGroups { + for _, stakeholderGroup := range r.StakeholderGroups { assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) } - for _, stakeholder := range createdMigrationWave.Stakeholders { + for _, stakeholder := range r.Stakeholders { assert.Must(t, Stakeholder.Delete(stakeholder.ID)) } - for _, app := range createdMigrationWave.Applications { + for _, app := range r.Applications { assert.Must(t, Application.Delete(app.ID)) } } diff --git a/test/api/migrationwave/samples.go b/test/api/migrationwave/samples.go index 99fe2fdad..535d5dbae 100644 --- a/test/api/migrationwave/samples.go +++ b/test/api/migrationwave/samples.go @@ -13,19 +13,16 @@ var Samples = []api.MigrationWave{ EndDate: time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local).Add(30 * time.Minute), Applications: []api.Ref{ { - ID: 1, Name: "Sample Application", }, }, Stakeholders: []api.Ref{ { - ID: 2, Name: "Sample Stakeholders", }, }, StakeholderGroups: []api.Ref{ { - ID: 3, Name: "Sample Stakeholders Groups", }, }, From 7ede7d029650052826f9eda8d176b41c9e0149a6 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 16 Aug 2023 20:43:31 +0530 Subject: [PATCH 7/7] updated ID name Signed-off-by: Yash Khare --- test/api/migrationwave/api_test.go | 84 +++++++++++++++++++++++++----- test/api/migrationwave/samples.go | 3 ++ 2 files changed, 74 insertions(+), 13 deletions(-) diff --git a/test/api/migrationwave/api_test.go b/test/api/migrationwave/api_test.go index 5cfbac367..afa2ac846 100644 --- a/test/api/migrationwave/api_test.go +++ b/test/api/migrationwave/api_test.go @@ -10,6 +10,35 @@ import ( func TestMigrationWaveCRUD(t *testing.T) { for _, r := range Samples { + createdApps := []api.Application{} + for _, app := range r.Applications { + expectedApp := api.Application{ + Name: app.Name, + Description: "Sample application", + } + assert.Must(t, Application.Create(&expectedApp)) + createdApps = append(createdApps, expectedApp) + } + + createdStakeholders := []api.Stakeholder{} + for _, stakeholder := range r.Stakeholders { + expectedStakeholder := api.Stakeholder{ + Name: stakeholder.Name, + Email: "sample@example.com", + } + assert.Must(t, Stakeholder.Create(&expectedStakeholder)) + createdStakeholders = append(createdStakeholders, expectedStakeholder) + } + + createdStakeholderGroups := []api.StakeholderGroup{} + for _, stakeholderGroup := range r.StakeholderGroups { + expectedStakeholderGroup := api.StakeholderGroup{ + Name: stakeholderGroup.Name, + Description: "Sample Stakeholder Group", + } + assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) + createdStakeholderGroups = append(createdStakeholderGroups, expectedStakeholderGroup) + } assert.Must(t, MigrationWave.Create(&r)) @@ -38,15 +67,15 @@ func TestMigrationWaveCRUD(t *testing.T) { // Delete created Applications, Stakeholders,StakeholdersGroup and MigrationWave assert.Must(t, MigrationWave.Delete(r.ID)) - for _, stakeholderGroup := range r.StakeholderGroups { + for _, stakeholderGroup := range createdStakeholderGroups { assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) } - for _, stakeholder := range r.Stakeholders { + for _, stakeholder := range createdStakeholders { assert.Must(t, Stakeholder.Delete(stakeholder.ID)) } - for _, app := range r.Applications { + for _, app := range createdApps { assert.Must(t, Application.Delete(app.ID)) } @@ -61,7 +90,37 @@ func TestMigrationWaveCRUD(t *testing.T) { func TestMigrationWaveList(t *testing.T) { createdMigrationWaves := []api.MigrationWave{} + createdApps := []api.Application{} + createdStakeholders := []api.Stakeholder{} + createdStakeholderGroups := []api.StakeholderGroup{} + for _, r := range Samples { + for _, app := range r.Applications { + expectedApp := api.Application{ + Name: app.Name, + Description: "Sample application", + } + assert.Must(t, Application.Create(&expectedApp)) + createdApps = append(createdApps, expectedApp) + } + + for _, stakeholder := range r.Stakeholders { + expectedStakeholder := api.Stakeholder{ + Name: stakeholder.Name, + Email: "sample@example.com", + } + assert.Must(t, Stakeholder.Create(&expectedStakeholder)) + createdStakeholders = append(createdStakeholders, expectedStakeholder) + } + + for _, stakeholderGroup := range r.StakeholderGroups { + expectedStakeholderGroup := api.StakeholderGroup{ + Name: stakeholderGroup.Name, + Description: "Sample Stakeholder Group", + } + assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup)) + createdStakeholderGroups = append(createdStakeholderGroups, expectedStakeholderGroup) + } assert.Must(t, MigrationWave.Create(&r)) createdMigrationWaves = append(createdMigrationWaves, r) } @@ -87,20 +146,19 @@ func TestMigrationWaveList(t *testing.T) { } for _, r := range createdMigrationWaves { - // Delete created Applications, Stakeholders,StakeholdersGroup and MigrationWave assert.Must(t, MigrationWave.Delete(r.ID)) + } - for _, stakeholderGroup := range r.StakeholderGroups { - assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) - } + for _, stakeholderGroup := range createdStakeholderGroups { + assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) + } - for _, stakeholder := range r.Stakeholders { - assert.Must(t, Stakeholder.Delete(stakeholder.ID)) - } + for _, stakeholder := range createdStakeholders { + assert.Must(t, Stakeholder.Delete(stakeholder.ID)) + } - for _, app := range r.Applications { - assert.Must(t, Application.Delete(app.ID)) - } + for _, app := range createdApps { + assert.Must(t, Application.Delete(app.ID)) } } diff --git a/test/api/migrationwave/samples.go b/test/api/migrationwave/samples.go index 535d5dbae..4c0ef9fa1 100644 --- a/test/api/migrationwave/samples.go +++ b/test/api/migrationwave/samples.go @@ -13,16 +13,19 @@ var Samples = []api.MigrationWave{ EndDate: time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local).Add(30 * time.Minute), Applications: []api.Ref{ { + ID: 1, Name: "Sample Application", }, }, Stakeholders: []api.Ref{ { + ID: 1, Name: "Sample Stakeholders", }, }, StakeholderGroups: []api.Ref{ { + ID: 1, Name: "Sample Stakeholders Groups", }, },