fix coverage script from masking unit test failures (#265)
* add 'set -e' line to fail on error
* create Unmarshal method for DefaultSecRule
* fix portsbinding 'update' unit test
* go fmt
* remove line from debugging
diff --git a/acceptance/openstack/compute/v2/quotaset_test.go b/acceptance/openstack/compute/v2/quotaset_test.go
index e0c4bae..1a691c0 100644
--- a/acceptance/openstack/compute/v2/quotaset_test.go
+++ b/acceptance/openstack/compute/v2/quotaset_test.go
@@ -69,7 +69,7 @@
}
for _, tenant := range allTenants {
- if tenant.Name == name{
+ if tenant.Name == name {
return tenant.ID, nil
}
}
@@ -120,49 +120,47 @@
}
idclient, err := clients.NewIdentityV2Client()
- if err != nil{
+ if err != nil {
t.Fatalf("Could not create IdentityClient to look up tenant id!")
}
tenantid, err := getTenantIDByName(t, idclient, os.Getenv("OS_TENANT_NAME"))
- if err != nil{
+ if err != nil {
t.Fatalf("Id for Tenant named '%' not found. Please set OS_TENANT_NAME appropriately", os.Getenv("OS_TENANT_NAME"))
}
-
//save original quotas
- orig, err := quotasets.Get(client,tenantid).Extract()
- th.AssertNoErr(t,err)
+ orig, err := quotasets.Get(client, tenantid).Extract()
+ th.AssertNoErr(t, err)
//Test Update
- res, err := quotasets.Update(client,tenantid,UpdatQuotaOpts).Extract()
- th.AssertNoErr(t,err)
- th.AssertEquals(t,UpdatedQuotas,*res)
+ res, err := quotasets.Update(client, tenantid, UpdatQuotaOpts).Extract()
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, UpdatedQuotas, *res)
//Test Delete
- _, err = quotasets.Delete(client,tenantid).Extract()
- th.AssertNoErr(t,err)
+ _, err = quotasets.Delete(client, tenantid).Extract()
+ th.AssertNoErr(t, err)
//We dont know the default quotas, so just check if the quotas are not the same as before
- newres, err := quotasets.Get(client,tenantid).Extract()
- if newres == res{
+ newres, err := quotasets.Get(client, tenantid).Extract()
+ if newres == res {
t.Fatalf("Quotas after delete equal quotas before delete!")
}
-
restore := quotasets.UpdateOpts{}
- FillUpdateOptsFromQuotaSet(*orig,&restore)
+ FillUpdateOptsFromQuotaSet(*orig, &restore)
//restore original quotas
- res, err = quotasets.Update(client,tenantid,restore).Extract()
- th.AssertNoErr(t,err)
+ res, err = quotasets.Update(client, tenantid, restore).Extract()
+ th.AssertNoErr(t, err)
orig.ID = ""
- th.AssertEquals(t,*orig,*res)
+ th.AssertEquals(t, *orig, *res)
}
// Makes sure that the FillUpdateOptsFromQuotaSet() helper function works properly
-func TestFillFromQuotaSetHelperFunction(t *testing.T){
+func TestFillFromQuotaSetHelperFunction(t *testing.T) {
op := "asets.UpdateOpts{}
expected := `
{
@@ -181,6 +179,6 @@
"server_groups": 2,
"server_group_members": 3
}`
- FillUpdateOptsFromQuotaSet(UpdatedQuotas,op)
- th.AssertJSONEquals(t,expected,op)
+ FillUpdateOptsFromQuotaSet(UpdatedQuotas, op)
+ th.AssertJSONEquals(t, expected, op)
}
diff --git a/acceptance/openstack/pkg.go b/acceptance/openstack/pkg.go
index 3a8ecdb..ef11064 100644
--- a/acceptance/openstack/pkg.go
+++ b/acceptance/openstack/pkg.go
@@ -1,4 +1,3 @@
// +build acceptance
package openstack
-
diff --git a/openstack/blockstorage/v1/apiversions/urls.go b/openstack/blockstorage/v1/apiversions/urls.go
index c9cf895..d1861ac 100644
--- a/openstack/blockstorage/v1/apiversions/urls.go
+++ b/openstack/blockstorage/v1/apiversions/urls.go
@@ -1,8 +1,8 @@
package apiversions
import (
- "strings"
"net/url"
+ "strings"
"github.com/gophercloud/gophercloud"
)
diff --git a/openstack/compute/v2/extensions/defsecrules/results.go b/openstack/compute/v2/extensions/defsecrules/results.go
index 61b918d..f990c99 100644
--- a/openstack/compute/v2/extensions/defsecrules/results.go
+++ b/openstack/compute/v2/extensions/defsecrules/results.go
@@ -1,6 +1,8 @@
package defsecrules
import (
+ "encoding/json"
+
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups"
"github.com/gophercloud/gophercloud/pagination"
@@ -10,6 +12,16 @@
// normal security rule.
type DefaultRule secgroups.Rule
+func (r *DefaultRule) UnmarshalJSON(b []byte) error {
+ var s secgroups.Rule
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = DefaultRule(s)
+ return nil
+}
+
// DefaultRulePage is a single page of a DefaultRule collection.
type DefaultRulePage struct {
pagination.SinglePageBase
diff --git a/openstack/compute/v2/extensions/quotasets/requests.go b/openstack/compute/v2/extensions/quotasets/requests.go
index 64fc8ff..bb9cb22 100644
--- a/openstack/compute/v2/extensions/quotasets/requests.go
+++ b/openstack/compute/v2/extensions/quotasets/requests.go
@@ -74,6 +74,3 @@
return gophercloud.BuildRequestBody(opts, "quota_set")
}
-
-
-
diff --git a/openstack/compute/v2/extensions/quotasets/testing/fixtures.go b/openstack/compute/v2/extensions/quotasets/testing/fixtures.go
index 0945f9b..79305a7 100644
--- a/openstack/compute/v2/extensions/quotasets/testing/fixtures.go
+++ b/openstack/compute/v2/extensions/quotasets/testing/fixtures.go
@@ -2,12 +2,12 @@
import (
"fmt"
- "net/http"
- "testing"
+ "github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
- "github.com/gophercloud/gophercloud"
+ "net/http"
+ "testing"
)
// GetOutput is a sample response to a Get call.
@@ -45,18 +45,16 @@
SecurityGroups: 10,
Cores: 200,
Instances: 25,
- ServerGroups: 2,
+ ServerGroups: 2,
ServerGroupMembers: 3,
}
-
//The expected update Body. Is also returned by PUT request
const UpdateOutput = `{"quota_set":{"cores":200,"fixed_ips":0,"floating_ips":0,"injected_file_content_bytes":10240,"injected_file_path_bytes":255,"injected_files":5,"instances":25,"key_pairs":10,"metadata_items":128,"ram":200000,"security_group_rules":20,"security_groups":10,"server_groups":2,"server_group_members":3}}`
//The expected partialupdate Body. Is also returned by PUT request
const PartialUpdateBody = `{"quota_set":{"cores":200, "force":true}}`
-
//Result of Quota-update
var UpdatedQuotaSet = quotasets.UpdateOpts{
FixedIps: gophercloud.IntToPointer(0),
@@ -71,7 +69,7 @@
SecurityGroups: gophercloud.IntToPointer(10),
Cores: gophercloud.IntToPointer(200),
Instances: gophercloud.IntToPointer(25),
- ServerGroups: gophercloud.IntToPointer(2),
+ ServerGroups: gophercloud.IntToPointer(2),
ServerGroupMembers: gophercloud.IntToPointer(3),
}
@@ -91,7 +89,7 @@
th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
- th.TestJSONRequest(t,r,UpdateOutput)
+ th.TestJSONRequest(t, r, UpdateOutput)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, UpdateOutput)
})
@@ -102,7 +100,7 @@
th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
- th.TestJSONRequest(t,r,PartialUpdateBody)
+ th.TestJSONRequest(t, r, PartialUpdateBody)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, UpdateOutput)
})
@@ -113,8 +111,8 @@
th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
- th.TestBody(t,r,"")
+ th.TestBody(t, r, "")
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(202)
})
-}
\ No newline at end of file
+}
diff --git a/openstack/compute/v2/extensions/quotasets/testing/requests_test.go b/openstack/compute/v2/extensions/quotasets/testing/requests_test.go
index e63f6aa..0193f97 100644
--- a/openstack/compute/v2/extensions/quotasets/testing/requests_test.go
+++ b/openstack/compute/v2/extensions/quotasets/testing/requests_test.go
@@ -3,11 +3,11 @@
import (
"testing"
+ "errors"
+ "github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
- "github.com/gophercloud/gophercloud"
- "errors"
)
func TestGet(t *testing.T) {
@@ -32,7 +32,7 @@
th.SetupHTTP()
defer th.TeardownHTTP()
HandlePartialPutSuccessfully(t)
- opts := quotasets.UpdateOpts{Cores:gophercloud.IntToPointer(200), Force:true}
+ opts := quotasets.UpdateOpts{Cores: gophercloud.IntToPointer(200), Force: true}
actual, err := quotasets.Update(client.ServiceClient(), FirstTenantID, opts).Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, &FirstQuotaSet, actual)
@@ -46,20 +46,19 @@
th.AssertNoErr(t, err)
}
-type ErrorUpdateOpts quotasets.UpdateOpts;
+type ErrorUpdateOpts quotasets.UpdateOpts
func (opts ErrorUpdateOpts) ToComputeQuotaUpdateMap() (map[string]interface{}, error) {
return nil, errors.New("This is an error")
}
-func TestErrorInToComputeQuotaUpdateMap(t *testing.T){
+func TestErrorInToComputeQuotaUpdateMap(t *testing.T) {
opts := &ErrorUpdateOpts{}
th.SetupHTTP()
defer th.TeardownHTTP()
HandlePutSuccessfully(t)
_, err := quotasets.Update(client.ServiceClient(), FirstTenantID, opts).Extract()
- if err == nil{
+ if err == nil {
t.Fatal("Error handling failed")
}
}
-
diff --git a/openstack/compute/v2/extensions/quotasets/urls.go b/openstack/compute/v2/extensions/quotasets/urls.go
index 4e15613..64190e9 100644
--- a/openstack/compute/v2/extensions/quotasets/urls.go
+++ b/openstack/compute/v2/extensions/quotasets/urls.go
@@ -18,4 +18,4 @@
func deleteURL(c *gophercloud.ServiceClient, tenantID string) string {
return getURL(c, tenantID)
-}
\ No newline at end of file
+}
diff --git a/openstack/compute/v2/images/results.go b/openstack/compute/v2/images/results.go
index a55b8f1..1090327 100644
--- a/openstack/compute/v2/images/results.go
+++ b/openstack/compute/v2/images/results.go
@@ -45,7 +45,7 @@
Status string
Updated string
-
+
Metadata map[string]string
}
diff --git a/openstack/networking/v2/extensions/portsbinding/testing/fixtures.go b/openstack/networking/v2/extensions/portsbinding/testing/fixtures.go
index 3231f66..f688c20 100644
--- a/openstack/networking/v2/extensions/portsbinding/testing/fixtures.go
+++ b/openstack/networking/v2/extensions/portsbinding/testing/fixtures.go
@@ -168,7 +168,8 @@
"f0ac4394-7e4a-4409-9701-ba8be283dbc3"
],
"binding:host_id": "HOST1",
- "binding:vnic_type": "normal"
+ "binding:vnic_type": "normal",
+ "allowed_address_pairs": null
}
}
`)
diff --git a/script/coverage b/script/coverage
index ab3a4f3..3efa81b 100755
--- a/script/coverage
+++ b/script/coverage
@@ -1,4 +1,7 @@
#!/bin/bash
+
+set -e
+
n=1
for testpkg in $(go list ./testing ./.../testing); do
covpkg="${testpkg/"/testing"/}"