Fixing up reflection issues on ListOpts builder

This commit is contained in:
Tom Carrio 2018-07-14 23:03:04 -04:00
parent 810a602a1b
commit a87c8fec38
2 changed files with 11 additions and 8 deletions

View File

@ -19,7 +19,7 @@ const (
// Retrieve the specific ImageDateFilter using the exported const from images
func getDateFilter(s string) (images.ImageDateFilter, error) {
filters := [...]images.ImageDateFilter{
filters := []images.ImageDateFilter{
images.FilterGT,
images.FilterGTE,
images.FilterLT,
@ -34,7 +34,8 @@ func getDateFilter(s string) (images.ImageDateFilter, error) {
}
}
return images.ImageDateFilter(nil), fmt.Errorf("No ImageDateFilter found for %s", s)
var badFilter images.ImageDateFilter
return badFilter, fmt.Errorf("No ImageDateFilter found for %s", s)
}
// Allows construction of all fields from ListOpts using the "q" tags and
@ -121,7 +122,7 @@ func applyMostRecent(listOpts *images.ListOpts) {
// Converts a given date entry to ImageDateQuery for use in ListOpts
func dateToImageDateQuery(val *string, key *string) (*images.ImageDateQuery, error) {
q := images.ImageDateQuery{}
q := new(images.ImageDateQuery)
sep := ":"
entries := strings.Split(*val, sep)
@ -140,7 +141,7 @@ func dateToImageDateQuery(val *string, key *string) (*images.ImageDateQuery, err
q.Date = date
}
return &q, nil
return q, nil
}
return nil, fmt.Errorf("Incorrect date query format for %s", key)

View File

@ -12,7 +12,7 @@ func TestGetImageFilter(t *testing.T) {
"lt": images.FilterLT,
"lte": images.FilterLTE,
"neq": images.FilterNEQ,
"ne": images.FilterEQ,
"eq": images.FilterEQ,
}
for passed, expected := range passedExpectedMap {
@ -20,7 +20,7 @@ func TestGetImageFilter(t *testing.T) {
if err != nil {
t.Errorf("Passed %s, received error: %s", passed, err.Error())
} else if filter != expected {
t.Errorf("Expected %s, got %s", string(expected), filter)
t.Errorf("Expected %s, got %s", expected, filter)
}
}
}
@ -53,11 +53,13 @@ func TestBuildImageFilter(t *testing.T) {
t.Errorf("Name did not parse correctly")
}
if testOpts.Visibility != images.ImageVisibility(filters["visibility"]) {
var visibility images.ImageVisibility = "public"
if testOpts.Visibility != visibility {
t.Errorf("Visibility did not parse correctly")
}
if testOpts.Status != images.ImageStatus(filters["image_status"]) {
var imageStatus images.ImageStatus = "active"
if testOpts.Status != imageStatus {
t.Errorf("Image status did not parse correctly")
}