diff --git a/builder/openstack/image_query.go b/builder/openstack/image_query.go index 5b2db0655..b86599801 100644 --- a/builder/openstack/image_query.go +++ b/builder/openstack/image_query.go @@ -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) diff --git a/builder/openstack/image_query_test.go b/builder/openstack/image_query_test.go index 90808bdaf..32f605a91 100644 --- a/builder/openstack/image_query_test.go +++ b/builder/openstack/image_query_test.go @@ -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") }