-
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 dependency directory necessary files
- Loading branch information
1 parent
171b155
commit 03b021e
Showing
5 changed files
with
183 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,51 @@ | ||
package binding | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/api" | ||
) | ||
|
||
// | ||
// Dependency API. | ||
type Dependency struct { | ||
// hub API client. | ||
client *Client | ||
} | ||
|
||
// | ||
// Create a Dependency. | ||
func (h *Dependency) Create(r *api.Dependency) (err error) { | ||
err = h.client.Post(api.DependenciesRoot, &r) | ||
return | ||
} | ||
|
||
// | ||
// Get a Dependency by ID. | ||
func (h *Dependency) Get(id uint) (r *api.Dependency, err error) { | ||
r = &api.Dependency{} | ||
path := Path(api.DependencyRoot).Inject(Params{api.ID: id}) | ||
err = h.client.Get(path, r) | ||
return | ||
} | ||
|
||
// | ||
// List Dependencies. | ||
func (h *Dependency) List() (list []api.Dependency, err error) { | ||
list = []api.Dependency{} | ||
err = h.client.Get(api.DependenciesRoot, &list) | ||
return | ||
} | ||
|
||
// | ||
// Update a Dependency. | ||
func (h *Dependency) Update(r *api.Dependency) (err error) { | ||
path := Path(api.DependencyRoot).Inject(Params{api.ID: r.From.ID}) | ||
err = h.client.Put(path, r) | ||
return | ||
} | ||
|
||
// | ||
// Delete a Dependency. | ||
func (h *Dependency) Delete(id uint) (err error) { | ||
err = h.client.Delete(Path(api.DependencyRoot).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,76 @@ | ||
package dependency | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/konveyor/tackle2-hub/test/assert" | ||
) | ||
|
||
func TestDependencyCRUD(t *testing.T) { | ||
for _, r := range Samples { | ||
t.Run("Dependency CRUD", func(t *testing.T) { | ||
// Create. | ||
err := Dependency.Create(&r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// Get. | ||
got, err := Dependency.Get(r.From.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.From.Name = "Updated " + r.From.Name | ||
err = Dependency.Update(&r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
got, err = Dependency.Get(r.From.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if got.From.Name != r.From.Name { | ||
t.Errorf("Different response error. Got %s, expected %s", got.From.Name, r.From.Name) | ||
} | ||
|
||
// Delete. | ||
err = Dependency.Delete(r.From.ID) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
_, err = Dependency.Get(r.From.ID) | ||
if err == nil { | ||
t.Errorf("Resource exits, but should be deleted: %v", r) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDependencyList(t *testing.T) { | ||
samples := Samples | ||
|
||
for name := range samples { | ||
sample := samples[name] | ||
assert.Must(t, Dependency.Create(&sample)) | ||
samples[name] = sample | ||
} | ||
|
||
got, err := Dependency.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, Dependency.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,19 @@ | ||
package dependency | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/binding" | ||
"github.com/konveyor/tackle2-hub/test/api/client" | ||
) | ||
|
||
var ( | ||
RichClient *binding.RichClient | ||
Dependency binding.Dependency | ||
) | ||
|
||
func init() { | ||
// Prepare RichClient and login to Hub API (configured from env variables). | ||
RichClient = client.PrepareRichClient() | ||
|
||
// Shortcut for Dependencyrelated RichClient methods. | ||
Dependency = RichClient.Dependency | ||
} |
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,32 @@ | ||
package dependency | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/api" | ||
) | ||
|
||
// Set of valid resources for tests and reuse. | ||
var ( | ||
firstDependency = api.Dependency{ | ||
To: api.Ref{ | ||
ID: uint(1473), | ||
Name: "Alice", | ||
}, | ||
From: api.Ref{ | ||
ID: uint(2), | ||
Name: "Bob", | ||
}, | ||
} | ||
|
||
secondDependency = api.Dependency{ | ||
To: api.Ref{ | ||
ID: uint(2123), | ||
Name: "Bob", | ||
}, | ||
From: api.Ref{ | ||
ID: uint(1), | ||
Name: "Alice", | ||
}, | ||
} | ||
|
||
Samples = []api.Dependency{firstDependency, secondDependency} | ||
) |