-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱 add migrationwave API test #471
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
87d9dd6
:seedling: add migrationwave API test
khareyash05 f15ef5f
update tests to add MigrationWave.List()
khareyash05 33b8ce8
updated code
khareyash05 46eda23
fix typos
khareyash05 0f426e2
updated check migrationwave function
khareyash05 bf4ab5e
update test and docs
khareyash05 7ede7d0
updated ID name
khareyash05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 MigrationWaves. | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
package migrationwave | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/konveyor/tackle2-hub/test/assert" | ||
) | ||
|
||
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)) | ||
|
||
// 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, MigrationWave.Delete(r.ID)) | ||
|
||
for _, stakeholderGroup := range createdStakeholderGroups { | ||
assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) | ||
} | ||
|
||
for _, stakeholder := range createdStakeholders { | ||
assert.Must(t, Stakeholder.Delete(stakeholder.ID)) | ||
} | ||
|
||
for _, app := range createdApps { | ||
assert.Must(t, Application.Delete(app.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 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)) | ||
khareyash05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
createdMigrationWaves = append(createdMigrationWaves, r) | ||
} | ||
|
||
// List MigrationWaves. | ||
got, err := MigrationWave.List() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// Compare contents of migration waves. | ||
for _, createdWave := range createdMigrationWaves { | ||
found := false | ||
for _, retrievedWave := range got { | ||
if assert.FlatEqual(createdWave.ID, retrievedWave.ID) { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Errorf("Expected Wave not found in the list: %v", createdWave) | ||
} | ||
} | ||
|
||
for _, r := range createdMigrationWaves { | ||
assert.Must(t, MigrationWave.Delete(r.ID)) | ||
} | ||
|
||
for _, stakeholderGroup := range createdStakeholderGroups { | ||
assert.Must(t, StakeholderGroup.Delete(stakeholderGroup.ID)) | ||
} | ||
|
||
for _, stakeholder := range createdStakeholders { | ||
assert.Must(t, Stakeholder.Delete(stakeholder.ID)) | ||
} | ||
|
||
for _, app := range createdApps { | ||
assert.Must(t, Application.Delete(app.ID)) | ||
} | ||
} | ||
|
||
func AssertEqualMigrationWaves(t *testing.T, got *api.MigrationWave, expected api.MigrationWave) { | ||
khareyash05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
} | ||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: 1, | ||
Name: "Sample Stakeholders", | ||
}, | ||
}, | ||
StakeholderGroups: []api.Ref{ | ||
{ | ||
ID: 1, | ||
Name: "Sample Stakeholders Groups", | ||
}, | ||
}, | ||
}, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one thing I missed before. I understand you cannot use r.Applications or r.Stakeholders directly since they're just Refs, but you need to preserve Refs IDs.
Currently this test creates Application&Stakeholder&StakeholderGroup with ID 1 (on empty database) and tries delete Application ID 1, Stakeholder ID 2, StakeholderGroup ID 3 (and leaves created Stakeholder&StakehoderGroup in the database).
Use IDs from Refs when creating these resources and ensure (just check manually on your local dev env) there are no remains in database after test execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya that seems an issue.Noticed how. Thanks for the check will update them