Fixing up reflection issues on ListOpts builder
This commit is contained in:
parent
810a602a1b
commit
a87c8fec38
|
@ -19,7 +19,7 @@ const (
|
||||||
|
|
||||||
// Retrieve the specific ImageDateFilter using the exported const from images
|
// Retrieve the specific ImageDateFilter using the exported const from images
|
||||||
func getDateFilter(s string) (images.ImageDateFilter, error) {
|
func getDateFilter(s string) (images.ImageDateFilter, error) {
|
||||||
filters := [...]images.ImageDateFilter{
|
filters := []images.ImageDateFilter{
|
||||||
images.FilterGT,
|
images.FilterGT,
|
||||||
images.FilterGTE,
|
images.FilterGTE,
|
||||||
images.FilterLT,
|
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
|
// 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
|
// Converts a given date entry to ImageDateQuery for use in ListOpts
|
||||||
func dateToImageDateQuery(val *string, key *string) (*images.ImageDateQuery, error) {
|
func dateToImageDateQuery(val *string, key *string) (*images.ImageDateQuery, error) {
|
||||||
q := images.ImageDateQuery{}
|
q := new(images.ImageDateQuery)
|
||||||
sep := ":"
|
sep := ":"
|
||||||
entries := strings.Split(*val, sep)
|
entries := strings.Split(*val, sep)
|
||||||
|
|
||||||
|
@ -140,7 +141,7 @@ func dateToImageDateQuery(val *string, key *string) (*images.ImageDateQuery, err
|
||||||
q.Date = date
|
q.Date = date
|
||||||
}
|
}
|
||||||
|
|
||||||
return &q, nil
|
return q, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("Incorrect date query format for %s", key)
|
return nil, fmt.Errorf("Incorrect date query format for %s", key)
|
||||||
|
|
|
@ -12,7 +12,7 @@ func TestGetImageFilter(t *testing.T) {
|
||||||
"lt": images.FilterLT,
|
"lt": images.FilterLT,
|
||||||
"lte": images.FilterLTE,
|
"lte": images.FilterLTE,
|
||||||
"neq": images.FilterNEQ,
|
"neq": images.FilterNEQ,
|
||||||
"ne": images.FilterEQ,
|
"eq": images.FilterEQ,
|
||||||
}
|
}
|
||||||
|
|
||||||
for passed, expected := range passedExpectedMap {
|
for passed, expected := range passedExpectedMap {
|
||||||
|
@ -20,7 +20,7 @@ func TestGetImageFilter(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Passed %s, received error: %s", passed, err.Error())
|
t.Errorf("Passed %s, received error: %s", passed, err.Error())
|
||||||
} else if filter != expected {
|
} 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")
|
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")
|
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")
|
t.Errorf("Image status did not parse correctly")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue