diff --git a/binding/application.go b/binding/application.go index d622d194f..b3970159e 100644 --- a/binding/application.go +++ b/binding/application.go @@ -11,32 +11,41 @@ type Application struct { client *Client } +// // Create a Application. func (h *Application) Create(r *api.Application) (err error) { err = h.client.Post(api.ApplicationsRoot, &r) return } -// Retrieve the Application. -func (h *Application) Get(r *api.Application) (err error) { - err = h.client.Get(Path(api.ApplicationRoot).Inject(Params{api.ID: r.ID}), &r) +// +// Get an application by ID. +func (h *Application) Get(id uint) (r *api.Application, err error) { + r = &api.Application{} + path := Path(api.ApplicationRoot).Inject(Params{api.ID: id}) + err = h.client.Get(path, r) return } -// Update the Application. -func (h *Application) Update(r *api.Application) (err error) { - err = h.client.Put(Path(api.ApplicationRoot).Inject(Params{api.ID: r.ID}), &r) +// +// List applications. +func (h *Application) List() (list []api.Application, err error) { + list = []api.Application{} + err = h.client.Get(api.ApplicationsRoot, &list) return } -// Delete the Application. -func (h *Application) Delete(r *api.Application) (err error) { - err = h.client.Delete(Path(api.ApplicationRoot).Inject(Params{api.ID: r.ID})) +// +// Update an application. +func (h *Application) Update(r *api.Application) (err error) { + path := Path(api.ApplicationRoot).Inject(Params{api.ID: r.ID}) + err = h.client.Put(path, r) return } -// List Applications. -func (h *Application) List(r []*api.Application) (err error) { - err = h.client.Get(api.ApplicationsRoot, &r) +// +// Delete the Application. +func (h *Application) Delete(id uint) (err error) { + err = h.client.Delete(Path(api.ApplicationRoot).Inject(Params{api.ID: id})) return } diff --git a/binding/richclient.go b/binding/richclient.go index 9b2dc5e90..6b27213f9 100644 --- a/binding/richclient.go +++ b/binding/richclient.go @@ -12,10 +12,10 @@ var ( ) func init() { - err := Settings.Load() - if err != nil { - panic(err) - } + err := Settings.Load() + if err != nil { + panic(err) + } } // The RichClient provides API integration. @@ -103,4 +103,4 @@ func (r *RichClient) Login(user, password string) (err error) { } r.client.SetToken(login.Token) return -} \ No newline at end of file +} diff --git a/test/api/application/bucket_test.go b/test/api/application/bucket_test.go index 37380d96b..1a1739fbb 100644 --- a/test/api/application/bucket_test.go +++ b/test/api/application/bucket_test.go @@ -22,5 +22,5 @@ func TestApplicationBucket(t *testing.T) { } // Clean the application. - assert.Must(t, Application.Delete(&application)) + assert.Must(t, Application.Delete(application.ID)) } diff --git a/test/api/application/create_get_delete_test.go b/test/api/application/create_get_delete_test.go index ba023e916..adb3e91af 100644 --- a/test/api/application/create_get_delete_test.go +++ b/test/api/application/create_get_delete_test.go @@ -14,9 +14,8 @@ func TestApplicationCreateGetDelete(t *testing.T) { assert.Should(t, Application.Create(&r)) // Try get. - got := api.Application{} - got.ID = r.ID - assert.Should(t, Application.Get(&got)) + got, err := Application.Get(r.ID) + assert.Should(t, err) // Assert the get response. if assert.FlatEqual(got, r) { @@ -24,14 +23,14 @@ func TestApplicationCreateGetDelete(t *testing.T) { } // Try list. - gotList := []*api.Application{} - assert.Should(t, Application.List(gotList)) + gotList, err := Application.List() + assert.Should(t, err) // Assert the list response. foundR := api.Application{} for _, listR := range gotList { if listR.Name == r.Name && listR.ID == r.ID { - foundR = *listR + foundR = listR break } } @@ -40,10 +39,10 @@ func TestApplicationCreateGetDelete(t *testing.T) { } // Try delete. - assert.Should(t, Application.Delete(&got)) + assert.Should(t, Application.Delete(got.ID)) // Check the created application was deleted. - err := Application.Get(&r) + _, err = Application.Get(r.ID) if err == nil { t.Fatalf("Exits, but should be deleted: %v", r) } @@ -68,11 +67,11 @@ func TestApplicationNotCreateDuplicates(t *testing.T) { t.Errorf("Created duplicate application: %v", dup) // Clean the duplicate. - assert.Must(t, Application.Delete(dup)) + assert.Must(t, Application.Delete(dup.ID)) } // Clean. - assert.Must(t, Application.Delete(&r)) + assert.Must(t, Application.Delete(r.ID)) } func TestApplicationNotCreateWithoutName(t *testing.T) { @@ -87,6 +86,6 @@ func TestApplicationNotCreateWithoutName(t *testing.T) { t.Errorf("Created empty application: %v", r) // Clean. - assert.Must(t, Application.Delete(r)) + assert.Must(t, Application.Delete(r.ID)) } } diff --git a/test/api/application/facts_test.go b/test/api/application/facts_test.go index 813676c44..56ce889a6 100644 --- a/test/api/application/facts_test.go +++ b/test/api/application/facts_test.go @@ -33,7 +33,7 @@ func TestApplicationFactCRUD(t *testing.T) { factPath := binding.Path(api.ApplicationFactRoot).Inject(binding.Params{api.ID: application.ID, api.Key: r.Key}) // Create. - err := Client.Post(factPath, &r) + err := Client.Post(binding.Path(api.ApplicationFactRoot).Inject(binding.Params{api.ID: application.ID}), &r) if err != nil { t.Errorf(err.Error()) } @@ -83,7 +83,7 @@ func TestApplicationFactCRUD(t *testing.T) { } // Clean the application. - assert.Must(t, Application.Delete(&application)) + assert.Must(t, Application.Delete(application.ID)) } func TestApplicationFactsList(t *testing.T) { @@ -97,7 +97,7 @@ func TestApplicationFactsList(t *testing.T) { for _, r := range SampleFacts { err := Client.Post(binding.Path(api.ApplicationFactRoot).Inject(binding.Params{api.ID: application.ID, api.Key: r.Key}), &r) if err != nil { - t.Fatalf(err.Error()) + t.Errorf(err.Error()) } } @@ -118,5 +118,5 @@ func TestApplicationFactsList(t *testing.T) { } // Clean the application. - assert.Must(t, Application.Delete(&application)) + assert.Must(t, Application.Delete(application.ID)) } diff --git a/test/api/application/update_test.go b/test/api/application/update_test.go index efbaef87e..1b1da85c2 100644 --- a/test/api/application/update_test.go +++ b/test/api/application/update_test.go @@ -5,7 +5,6 @@ import ( "reflect" "testing" - "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/test/assert" ) @@ -21,15 +20,14 @@ func TestApplicationUpdateName(t *testing.T) { assert.Should(t, Application.Update(&update)) // Check the updated. - got := api.Application{} - got.ID = r.ID - assert.Should(t, Application.Get(&got)) + got, err := Application.Get(r.ID) + assert.Should(t, err) if !reflect.DeepEqual(got.Name, update.Name) { t.Errorf("Different updated name error. Got %v, expected %v", got.Name, update.Name) } // Clean. - assert.Must(t, Application.Delete(&r)) + assert.Must(t, Application.Delete(r.ID)) }) } }