-
Notifications
You must be signed in to change notification settings - Fork 34
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
2 changed files
with
143 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,86 @@ | ||
package stakeholdergroup | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/konveyor/tackle2-hub/test/api/client" | ||
) | ||
|
||
func TestStakeholderGroupCRUD(t *testing.T) { | ||
samples := CloneSamples() | ||
|
||
for _, r := range samples { | ||
t.Run(r.Name, func(t *testing.T) { | ||
// Create. | ||
err := Client.Post(api.StakeholderGroupsRoot, &r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
rPath := fmt.Sprintf("%s/%d", api.StakeholderGroupsRoot, r.ID) | ||
|
||
// Get. | ||
gotR := api.StakeholderGroup{} | ||
err = Client.Get(rPath, &gotR) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if client.FlatEqual(gotR, r) { | ||
t.Errorf("Different response error. Got %v, expected %v", gotR, r) | ||
} | ||
|
||
// Update. | ||
updatedR := api.StakeholderGroup{ | ||
Name: "Updated " + r.Name, | ||
} | ||
err = Client.Put(rPath, updatedR) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
err = Client.Get(rPath, &gotR) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if gotR.Name != updatedR.Name { | ||
t.Errorf("Different response error. Got %s, expected %s", gotR.Name, updatedR.Name) | ||
} | ||
|
||
// Delete. | ||
err = Client.Delete(rPath) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
err = Client.Get(rPath, &r) | ||
if err == nil { | ||
t.Errorf("Resource exits, but should be deleted: %v", r) | ||
} | ||
|
||
// Cleanup. | ||
Delete(t, r) | ||
}) | ||
} | ||
} | ||
|
||
func TestStakeholderGroupList(t *testing.T) { | ||
samples := CloneSamples() | ||
for _, r := range samples { | ||
Create(t, r) | ||
} | ||
|
||
gotList := []api.StakeholderGroup{} | ||
err := Client.Get(api.TagCategoriesRoot, &gotList) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if client.FlatEqual(gotList, samples) { | ||
t.Errorf("Different response error. Got %v, expected %v", gotList, samples) | ||
} | ||
|
||
for _, r := range samples { | ||
Delete(t, r) | ||
} | ||
|
||
} |
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,57 @@ | ||
package stakeholdergroup | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/konveyor/tackle2-hub/test/api/client" | ||
) | ||
|
||
var ( | ||
// Setup Hub API client | ||
Client = client.Client | ||
) | ||
|
||
// | ||
// Set of valid resources for tests and reuse. | ||
var Samples = []*api.StakeholderGroup{ | ||
{ | ||
Name: "Mgmt", | ||
Description: "Management stakeholder group.", | ||
}, | ||
{ | ||
Name: "Engineering", | ||
Description: "Engineering team.", | ||
}, | ||
} | ||
|
||
// | ||
// Creates a copy of Samples for a test. | ||
func CloneSamples() (samples []*api.StakeholderGroup) { | ||
raw, err := json.Marshal(Samples) | ||
if err != nil { | ||
fmt.Print("ERROR cloning samples") | ||
} | ||
json.Unmarshal(raw, &samples) | ||
return | ||
} | ||
|
||
// | ||
// Create. | ||
func Create(t *testing.T, r *api.StakeholderGroup) { | ||
err := Client.Post(api.StakeholderGroupsRoot, &r) | ||
if err != nil { | ||
t.Fatalf("Create fatal error: %v", err.Error()) | ||
} | ||
} | ||
|
||
// | ||
// Delete. | ||
func Delete(t *testing.T, r *api.StakeholderGroup) { | ||
err := Client.Delete(fmt.Sprintf("%s/%d", api.StakeholderGroupsRoot, r.ID)) | ||
if err != nil { | ||
t.Fatalf("Delete fatal error: %v", err.Error()) | ||
} | ||
} |