-
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 Setting, Schema basic API tests (#580)
Adding basic API test for following resources: - Setting - basic CRUD - Schema - Get --------- Signed-off-by: Marek Aufart <[email protected]>
- Loading branch information
Showing
6 changed files
with
165 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
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 schema | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/konveyor/tackle2-hub/api" | ||
) | ||
|
||
func TestGetSchema(t *testing.T) { | ||
// Get. | ||
schema := api.Schema{} | ||
err := RichClient.Client.Get("/schema", &schema) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if len(schema.Paths) < 1 { | ||
t.Errorf("Got empty Paths from /schema.") | ||
} | ||
} |
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,16 @@ | ||
package schema | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/binding" | ||
"github.com/konveyor/tackle2-hub/test/api/client" | ||
) | ||
|
||
var ( | ||
RichClient *binding.RichClient | ||
) | ||
|
||
|
||
func init() { | ||
// Prepare RichClient and login to Hub API (configured from env variables). | ||
RichClient = client.PrepareRichClient() | ||
} |
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,64 @@ | ||
package setting | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSettingCRUD(t *testing.T) { | ||
for _, r := range Samples { | ||
t.Run(r.Key, func(t *testing.T) { | ||
// Create. | ||
err := Setting.Create(&r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
// Get. | ||
gotValue := "" | ||
err = Setting.Get(r.Key, &gotValue) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if gotValue != r.Value { | ||
t.Errorf("Different response error. Got %v, expected %v", gotValue, r) | ||
} | ||
|
||
// Update. | ||
updateValue := "data-updated" | ||
r.Value = updateValue | ||
err = Setting.Update(&r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
err = Setting.Get(r.Key, &r) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if r.Value != updateValue { | ||
t.Errorf("Different Setting Value error. Got %s, expected %s", gotValue, updateValue) | ||
} | ||
|
||
// Delete. | ||
err = Setting.Delete(r.Key) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
err = Setting.Get(r.Key, gotValue) | ||
if err == nil { | ||
t.Errorf("Resource exits, but should be deleted: %v", r) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSettingList(t *testing.T) { | ||
got, err := Setting.List() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if len(got) < 1 { | ||
t.Errorf("Got empty Settings list.") | ||
} | ||
} |
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 setting | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/binding" | ||
"github.com/konveyor/tackle2-hub/test/api/client" | ||
) | ||
|
||
var ( | ||
RichClient *binding.RichClient | ||
Setting binding.Setting | ||
) | ||
|
||
|
||
func init() { | ||
// Prepare RichClient and login to Hub API (configured from env variables). | ||
RichClient = client.PrepareRichClient() | ||
|
||
// Shortcut for Setting-related RichClient methods. | ||
Setting = RichClient.Setting | ||
} |
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,15 @@ | ||
package setting | ||
|
||
import ( | ||
"github.com/konveyor/tackle2-hub/api" | ||
) | ||
|
||
// Set of valid resources for tests and reuse. | ||
var ( | ||
SampleSetting = api.Setting{ | ||
Key: "sample.setting.1", | ||
Value: "data-123", | ||
} | ||
|
||
Samples = []api.Setting{SampleSetting} | ||
) |