-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add review API Test Work to be Done 1. Check for Review.List() 2. Check for Copy Root --------- Signed-off-by: Yash Khare <yash2010118@akgec.ac.in>
- Loading branch information
1 parent
a51c0eb
commit b05ee5e
Showing
6 changed files
with
283 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package binding | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/api" | ||
) | ||
|
||
// | ||
// Review API. | ||
type Review struct { | ||
client *Client | ||
} | ||
|
||
// | ||
// Create a Review. | ||
func (h *Review) Create(r *api.Review) (err error) { | ||
err = h.client.Post(api.ReviewsRoot, &r) | ||
return | ||
} | ||
|
||
// | ||
// Get a Review by ID. | ||
func (h *Review) Get(id uint) (r *api.Review, err error) { | ||
r = &api.Review{} | ||
path := Path(api.ReviewRoot).Inject(Params{api.ID: id}) | ||
err = h.client.Get(path, r) | ||
return | ||
} | ||
|
||
// | ||
// List Reviews. | ||
func (h *Review) List() (list []api.Review, err error) { | ||
list = []api.Review{} | ||
err = h.client.Get(api.ReviewsRoot, &list) | ||
return | ||
} | ||
|
||
// | ||
// Update a Review. | ||
func (h *Review) Update(r *api.Review) (err error) { | ||
path := Path(api.ReviewRoot).Inject(Params{api.ID: r.ID}) | ||
err = h.client.Put(path, r) | ||
return | ||
} | ||
|
||
// | ||
// Delete a Review. | ||
func (h *Review) Delete(id uint) (err error) { | ||
err = h.client.Delete(Path(api.ReviewRoot).Inject(Params{api.ID: id})) | ||
return | ||
} | ||
|
||
// | ||
// Copy a Review. | ||
func (h *Review) Copy(reviewID uint, appID uint) (err error) { | ||
copyRequest := api.CopyRequest{ | ||
SourceReview: reviewID, | ||
TargetApplications: []uint{appID}, | ||
} | ||
err = h.client.Post(api.CopyRoot, copyRequest) | ||
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,164 @@ | ||
package review | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/konveyor/tackle2-hub/test/assert" | ||
) | ||
|
||
func TestReviewCRUD(t *testing.T) { | ||
for _, r := range Samples { | ||
t.Run("Review CRUD", func(t *testing.T) { | ||
|
||
// Create Application and Review. | ||
app := api.Application{ | ||
Name: r.Application.Name, | ||
Description: "Application for Review", | ||
} | ||
assert.Must(t, Application.Create(&app)) | ||
|
||
// Update Application ID with the Sample Id. | ||
r.Application.ID = app.ID | ||
|
||
assert.Must(t, Review.Create(&r)) | ||
|
||
// Get. | ||
got, err := Review.Get(r.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// Compare got values with expected values. | ||
AssertEqualReviews(t, got, r) | ||
|
||
// Update Comments and Effort Estimate. | ||
r.Comments = "Updated Comment " + r.Comments | ||
assert.Should(t, Review.Update(&r)) | ||
|
||
// Find Review and check its parameters with the got(On Updation). | ||
got, err = Review.Get(r.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// Check if the unchanged values remain same or not. | ||
AssertEqualReviews(t, got, r) | ||
|
||
// Delete Related Applications. | ||
assert.Must(t, Application.Delete(app.ID)) | ||
// Delete Review. | ||
assert.Must(t, Review.Delete(r.ID)) | ||
|
||
// Check if the review is present even after deletion or not. | ||
_, err = Review.Get(r.ID) | ||
if err == nil { | ||
t.Errorf("Resource exits, but should be deleted: %v", r) | ||
} | ||
}) | ||
|
||
t.Run("Copy Review", func(t *testing.T) { | ||
|
||
// Create Application and Review. | ||
srcApp := api.Application{ | ||
Name: r.Application.Name, | ||
Description: "Application for Review", | ||
} | ||
assert.Must(t, Application.Create(&srcApp)) | ||
|
||
// Update Application ID with the Sample Id. | ||
r.Application.ID = srcApp.ID | ||
|
||
assert.Must(t, Review.Create(&r)) | ||
|
||
// Create another application to copy | ||
destApp := api.Application{ | ||
Name: "New Application", | ||
Description: "Application for Review", | ||
Review: &api.Ref{ | ||
ID: r.ID, | ||
}, | ||
} | ||
assert.Must(t, Application.Create(&destApp)) | ||
|
||
err := Review.Copy(r.ID, destApp.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
gotReview, err := Review.Get(destApp.Review.ID) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// Check if the expcted review and got review is same. | ||
AssertEqualReviews(t, gotReview, r) | ||
|
||
// Delete Review. | ||
assert.Must(t, Review.Delete(r.ID)) | ||
|
||
// Delete Applications. | ||
assert.Must(t, Application.Delete(srcApp.ID)) | ||
assert.Must(t, Application.Delete(destApp.ID)) | ||
}) | ||
} | ||
} | ||
|
||
func TestReviewList(t *testing.T) { | ||
createdReviews := []api.Review{} | ||
|
||
for _, r := range Samples { | ||
app := api.Application{ | ||
Name: r.Application.Name, | ||
Description: "Application for Review", | ||
} | ||
assert.Must(t, Application.Create(&app)) | ||
|
||
r.Application.ID = app.ID | ||
assert.Should(t, Review.Create(&r)) | ||
createdReviews = append(createdReviews, r) | ||
} | ||
|
||
// List Reviews. | ||
got, err := Review.List() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// check if created Reviews are in the list we got from Review.List() | ||
for _, createdReview := range createdReviews { | ||
found := false | ||
for _, retrievedReview := range got { | ||
if assert.FlatEqual(createdReview.ID, retrievedReview.ID) { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Errorf("Expected review not found in the list: %v", createdReview) | ||
} | ||
} | ||
|
||
// Delete related reviews and applications. | ||
for _, review := range createdReviews { | ||
assert.Must(t, Application.Delete(review.ID)) | ||
assert.Must(t, Review.Delete(review.ID)) | ||
} | ||
} | ||
|
||
func AssertEqualReviews(t *testing.T, got *api.Review, expected api.Review) { | ||
if got.BusinessCriticality != expected.BusinessCriticality { | ||
t.Errorf("Different Business Criticality Got %v, expected %v", got.BusinessCriticality, expected.BusinessCriticality) | ||
} | ||
if got.EffortEstimate != expected.EffortEstimate { | ||
t.Errorf("Different Effort Estimate Got %v, expected %v", got.EffortEstimate, expected.EffortEstimate) | ||
} | ||
if got.ProposedAction != expected.ProposedAction { | ||
t.Errorf("Different Proposed Action Got %v, expected %v", got.ProposedAction, expected.ProposedAction) | ||
} | ||
if got.WorkPriority != expected.WorkPriority { | ||
t.Errorf("Different Work Priority Got %v, expected %v", got.WorkPriority, expected.WorkPriority) | ||
} | ||
} |
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,23 @@ | ||
package review | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/binding" | ||
"github.com/konveyor/tackle2-hub/test/api/client" | ||
) | ||
|
||
var ( | ||
RichClient *binding.RichClient | ||
Review binding.Review | ||
Application binding.Application | ||
) | ||
|
||
func init() { | ||
// Prepare RichClient and login to Hub API (configured from env variables). | ||
RichClient = client.PrepareRichClient() | ||
|
||
// Shortcut for Review-related RichClient methods. | ||
Review = RichClient.Review | ||
|
||
// Shortcut for Application-related RichClient methods. | ||
Application = RichClient.Application | ||
} |
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,30 @@ | ||
package review | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/api" | ||
) | ||
|
||
var Samples = []api.Review{ | ||
{ | ||
BusinessCriticality: 1, | ||
EffortEstimate: "min", | ||
ProposedAction: "run", | ||
WorkPriority: 1, | ||
Comments: "nil", | ||
Application: api.Ref{ | ||
ID: 1, | ||
Name: "Sample Review 1", | ||
}, | ||
}, | ||
{ | ||
BusinessCriticality: 2, | ||
EffortEstimate: "max", | ||
ProposedAction: "stop", | ||
WorkPriority: 2, | ||
Comments: "nil", | ||
Application: api.Ref{ | ||
ID: 2, | ||
Name: "Sample Review 2", | ||
}, | ||
}, | ||
} |