-
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.
Signed-off-by: Marek Aufart <[email protected]>
- Loading branch information
Showing
5 changed files
with
208 additions
and
0 deletions.
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,50 @@ | ||
package binding | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/api" | ||
) | ||
|
||
// | ||
// Assessment API. | ||
type Assessment struct { | ||
client *Client | ||
} | ||
|
||
// | ||
// Create a Assessment. | ||
func (h *Assessment) Create(r *api.Assessment) (err error) { | ||
err = h.client.Post(api.AssessmentsRoot, &r) | ||
return | ||
} | ||
|
||
// | ||
// Get a Assessment by ID. | ||
func (h *Assessment) Get(id uint) (r *api.Assessment, err error) { | ||
r = &api.Assessment{} | ||
path := Path(api.AssessmentRoot).Inject(Params{api.ID: id}) | ||
err = h.client.Get(path, r) | ||
return | ||
} | ||
|
||
// | ||
// List Assessments. | ||
func (h *Assessment) List() (list []api.Assessment, err error) { | ||
list = []api.Assessment{} | ||
err = h.client.Get(api.AssessmentsRoot, &list) | ||
return | ||
} | ||
|
||
// | ||
// Update a Assessment. | ||
func (h *Assessment) Update(r *api.Assessment) (err error) { | ||
path := Path(api.AssessmentRoot).Inject(Params{api.ID: r.ID}) | ||
err = h.client.Put(path, r) | ||
return | ||
} | ||
|
||
// | ||
// Delete a Assessment. | ||
func (h *Assessment) Delete(id uint) (err error) { | ||
err = h.client.Delete(Path(api.AssessmentRoot).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package assessment | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/konveyor/tackle2-hub/test/assert" | ||
) | ||
|
||
func TestAssessmentCRUD(t *testing.T) { | ||
for _, r := range Samples { | ||
t.Run(fmt.Sprintf("%s for application %s", r.Questionnaire.Name, r.Application.Name), func(t *testing.T) { | ||
// Create. | ||
err := Assessment.Create(&r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// Get. | ||
got, err := Assessment.Get(r.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if assert.FlatEqual(got, r) { | ||
t.Errorf("Different response error. Got %v, expected %v", got, r) | ||
} | ||
|
||
// Update. | ||
r.Name = "Updated " + r.Name | ||
r.Required = false | ||
err = Assessment.Update(&r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
got, err = Assessment.Get(r.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if got.Name != r.Name { | ||
Check failure on line 40 in test/api/assessment/api_test.go GitHub Actions / test-api
|
||
t.Errorf("Different response error. Got %s, expected %s", got.Name, r.Name) | ||
Check failure on line 41 in test/api/assessment/api_test.go GitHub Actions / test-api
|
||
} | ||
if got.Required != false { | ||
t.Errorf("Required should be false after update. Got %+v, expected %+v", got, r) | ||
} | ||
|
||
// Delete. | ||
err = Assessment.Delete(r.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
_, err = Assessment.Get(r.ID) | ||
if err == nil { | ||
t.Errorf("Resource exits, but should be deleted: %v", r) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAssessmentList(t *testing.T) { | ||
samples := Samples | ||
|
||
for name := range samples { | ||
sample := samples[name] | ||
assert.Must(t, Assessment.Create(&sample)) | ||
samples[name] = sample | ||
} | ||
|
||
got, err := Assessment.List() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if assert.FlatEqual(got, &samples) { | ||
t.Errorf("Different response error. Got %v, expected %v", got, samples) | ||
} | ||
|
||
for _, r := range samples { | ||
assert.Must(t, Assessment.Delete(r.ID)) | ||
} | ||
} |
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,20 @@ | ||
package assessment | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/binding" | ||
"github.com/konveyor/tackle2-hub/test/api/client" | ||
) | ||
|
||
var ( | ||
RichClient *binding.RichClient | ||
Assessment binding.Assessment | ||
) | ||
|
||
|
||
func init() { | ||
// Prepare RichClient and login to Hub API (configured from env variables). | ||
RichClient = client.PrepareRichClient() | ||
|
||
// Shortcut for Assessment-related RichClient methods. | ||
Assessment = RichClient.Assessment | ||
} |
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,53 @@ | ||
package assessment | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/konveyor/tackle2-hub/assessment" | ||
"github.com/konveyor/tackle2-hub/test/api/application" | ||
"github.com/konveyor/tackle2-hub/test/api/questionnaire" | ||
) | ||
|
||
// Set of valid resources for tests and reuse. | ||
var ( | ||
Assessment1 = api.Assessment{ | ||
// Ref resource are created by the test. | ||
Application: &api.Ref{ | ||
Name: application.Minimal.Name, | ||
}, | ||
Questionnaire: api.Ref{ | ||
Name: questionnaire.Questionnaire1.Name, | ||
}, | ||
Sections: []assessment.Section{ | ||
{ | ||
Order: 1, | ||
Name: "Section 1", | ||
Questions: []assessment.Question{ | ||
{ | ||
Order: 1, | ||
Text: "What is your favorite color?", | ||
Explanation: "Please tell us your favorite color.", | ||
Answers: []assessment.Answer{ | ||
{ | ||
Order: 1, | ||
Text: "Red", | ||
Risk: "red", | ||
}, | ||
{ | ||
Order: 2, | ||
Text: "Green", | ||
Risk: "green", | ||
}, | ||
{ | ||
Order: 3, | ||
Text: "Blue", | ||
Risk: "yellow", | ||
Selected: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
Samples = []api.Assessment{Assessment1} | ||
) |