correctly vendor gophercloud dep

This commit is contained in:
Matthew Hooker 2016-12-13 15:23:30 -08:00
parent 7bd211cf61
commit 9d7df95cdf
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
13 changed files with 96 additions and 998 deletions

View File

@ -1,5 +0,0 @@
#!/bin/bash
#
# Run the acceptance tests.
exec go test -p=1 github.com/gophercloud/gophercloud/acceptance/... $@

View File

@ -1,173 +0,0 @@
#!/bin/bash
#
# This script is useful for creating a devstack environment to run gophercloud
# acceptance tests on.
#
# This can be considered a "legacy" devstack environment since it uses
# Keystone v2 and LBaaS v1.
#
# To run, simply execute this script within a virtual machine.
#
# The following OpenStack versions are installed:
# * OpenStack Mitaka
# * Keystone v2
# * Glance v1 and v2
# * Nova v2 and v2.1
# * Cinder v1 and v2
# * Trove v1
# * Swift v1
# * Neutron v2
# * Neutron LBaaS v1.0
# * Neutron FWaaS v2.0
# * Manila v2
#
# Go 1.6 is also installed.
set -e
cd
sudo apt-get update
sudo apt-get install -y git make mercurial
sudo wget -O /usr/local/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
sudo chmod +x /usr/local/bin/gimme
gimme 1.6 >> .bashrc
mkdir ~/go
eval "$(/usr/local/bin/gimme 1.6)"
echo 'export GOPATH=$HOME/go' >> .bashrc
export GOPATH=$HOME/go
source .bashrc
go get golang.org/x/crypto/ssh
go get github.com/gophercloud/gophercloud
git clone https://git.openstack.org/openstack-dev/devstack -b stable/mitaka
cd devstack
cat >local.conf <<EOF
[[local|localrc]]
# OpenStack version
OPENSTACK_VERSION="mitaka"
# devstack password
DEVSTACK_PASSWORD="password"
# Configure passwords and the Swift Hash
MYSQL_PASSWORD=\$DEVSTACK_PASSWORD
RABBIT_PASSWORD=\$DEVSTACK_PASSWORD
SERVICE_TOKEN=\$DEVSTACK_PASSWORD
ADMIN_PASSWORD=\$DEVSTACK_PASSWORD
SERVICE_PASSWORD=\$DEVSTACK_PASSWORD
SWIFT_HASH=\$DEVSTACK_PASSWORD
# Configure the stable OpenStack branches used by DevStack
# For stable branches see
# http://git.openstack.org/cgit/openstack-dev/devstack/refs/
CINDER_BRANCH=stable/\$OPENSTACK_VERSION
CEILOMETER_BRANCH=stable/\$OPENSTACK_VERSION
GLANCE_BRANCH=stable/\$OPENSTACK_VERSION
HEAT_BRANCH=stable/\$OPENSTACK_VERSION
HORIZON_BRANCH=stable/\$OPENSTACK_VERSION
KEYSTONE_BRANCH=stable/\$OPENSTACK_VERSION
NEUTRON_BRANCH=stable/\$OPENSTACK_VERSION
NOVA_BRANCH=stable/\$OPENSTACK_VERSION
SWIFT_BRANCH=stable/\$OPENSTACK_VERSION
ZAQAR_BRANCH=stable/\$OPENSTACK_VERSION
# Enable Swift
enable_service s-proxy
enable_service s-object
enable_service s-container
enable_service s-account
# Disable Nova Network and enable Neutron
disable_service n-net
enable_service q-svc
enable_service q-agt
enable_service q-dhcp
enable_service q-l3
enable_service q-meta
#enable_service q-flavors
# Disable Neutron metering
disable_service q-metering
# Enable LBaaS V1
enable_service q-lbaas
# Enable FWaaS
enable_service q-fwaas
# Enable LBaaS v2
#enable_plugin neutron-lbaas https://git.openstack.org/openstack/neutron-lbaas stable/\$OPENSTACK_VERSION
#enable_plugin octavia https://git.openstack.org/openstack/octavia stable/\$OPENSTACK_VERSION
#enable_service q-lbaasv2
#enable_service octavia
#enable_service o-cw
#enable_service o-hk
#enable_service o-hm
#enable_service o-api
# Enable Trove
enable_plugin trove git://git.openstack.org/openstack/trove.git stable/\$OPENSTACK_VERSION
enable_service trove,tr-api,tr-tmgr,tr-cond
# Disable Temptest
disable_service tempest
# Disable Horizon
disable_service horizon
# Disable Keystone v2
#ENABLE_IDENTITY_V2=False
# Enable SSL/tls
#enable_service tls-proxy
#USE_SSL=True
# Enable Ceilometer
#enable_service ceilometer-acompute
#enable_service ceilometer-acentral
#enable_service ceilometer-anotification
#enable_service ceilometer-collector
#enable_service ceilometer-alarm-evaluator
#enable_service ceilometer-alarm-notifier
#enable_service ceilometer-api
# Enable Zaqar
#enable_plugin zaqar https://github.com/openstack/zaqar
#enable_service zaqar-server
# Enable Manila
enable_plugin manila https://github.com/openstack/manila
# Automatically download and register a VM image that Heat can launch
# For more information on Heat and DevStack see
# http://docs.openstack.org/developer/heat/getting_started/on_devstack.html
#IMAGE_URLS+=",http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2"
#IMAGE_URLS+=",https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img"
# Logging
LOGDAYS=1
LOGFILE=/opt/stack/logs/stack.sh.log
LOGDIR=/opt/stack/logs
EOF
./stack.sh
# Prep the testing environment by creating the required testing resources and environment variables
source openrc admin
wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
glance image-create --name CirrOS --disk-format qcow2 --container-format bare < cirros-0.3.4-x86_64-disk.img
nova flavor-create m1.acctest 99 512 5 1 --ephemeral 10
nova flavor-create m1.resize 98 512 6 1 --ephemeral 10
_NETWORK_ID=$(nova net-list | grep private | awk -F\| '{print $2}' | tr -d ' ')
_EXTGW_ID=$(nova net-list | grep public | awk -F\| '{print $2}' | tr -d ' ')
_IMAGE_ID=$(nova image-list | grep CirrOS | awk -F\| '{print $2}' | tr -d ' ' | head -1)
echo export OS_IMAGE_NAME="cirros-0.3.4-x86_64-uec" >> openrc
echo export OS_IMAGE_ID="$_IMAGE_ID" >> openrc
echo export OS_NETWORK_ID=$_NETWORK_ID >> openrc
echo export OS_EXTGW_ID=$_EXTGW_ID >> openrc
echo export OS_POOL_NAME="public" >> openrc
echo export OS_FLAVOR_ID=99 >> openrc
echo export OS_FLAVOR_ID_RESIZE=98 >> openrc
source openrc demo

View File

@ -1,208 +0,0 @@
#!/bin/bash
#
# This script is useful for creating a devstack environment to run gophercloud
# acceptance tests on.
#
# To run, simply execute this script within a virtual machine.
#
# The following OpenStack versions are installed:
# * OpenStack Mitaka
# * Keystone v3
# * Glance v1 and v2
# * Nova v2 and v2.1
# * Cinder v1 and v2
# * Trove v1
# * Swift v1
# * Neutron v2
# * Neutron LBaaS v2.0
# * Neutron FWaaS v2.0
#
# Go 1.6 is also installed.
set -e
cd
sudo apt-get update
sudo apt-get install -y git make mercurial
sudo wget -O /usr/local/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
sudo chmod +x /usr/local/bin/gimme
gimme 1.6 >> .bashrc
mkdir ~/go
eval "$(/usr/local/bin/gimme 1.6)"
echo 'export GOPATH=$HOME/go' >> .bashrc
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/terraform:$HOME/go/bin
echo 'export PATH=$PATH:$HOME/terraform:$HOME/go/bin' >> .bashrc
source .bashrc
go get golang.org/x/crypto/ssh
go get github.com/gophercloud/gophercloud
git clone https://git.openstack.org/openstack-dev/devstack -b stable/mitaka
cd devstack
cat >local.conf <<EOF
[[local|localrc]]
# OpenStack version
OPENSTACK_VERSION="mitaka"
# devstack password
DEVSTACK_PASSWORD="password"
# Configure passwords and the Swift Hash
MYSQL_PASSWORD=\$DEVSTACK_PASSWORD
RABBIT_PASSWORD=\$DEVSTACK_PASSWORD
SERVICE_TOKEN=\$DEVSTACK_PASSWORD
ADMIN_PASSWORD=\$DEVSTACK_PASSWORD
SERVICE_PASSWORD=\$DEVSTACK_PASSWORD
SWIFT_HASH=\$DEVSTACK_PASSWORD
# Configure the stable OpenStack branches used by DevStack
# For stable branches see
# http://git.openstack.org/cgit/openstack-dev/devstack/refs/
CINDER_BRANCH=stable/\$OPENSTACK_VERSION
CEILOMETER_BRANCH=stable/\$OPENSTACK_VERSION
GLANCE_BRANCH=stable/\$OPENSTACK_VERSION
HEAT_BRANCH=stable/\$OPENSTACK_VERSION
HORIZON_BRANCH=stable/\$OPENSTACK_VERSION
KEYSTONE_BRANCH=stable/\$OPENSTACK_VERSION
NEUTRON_BRANCH=stable/\$OPENSTACK_VERSION
NOVA_BRANCH=stable/\$OPENSTACK_VERSION
SWIFT_BRANCH=stable/\$OPENSTACK_VERSION
ZAQAR_BRANCH=stable/\$OPENSTACK_VERSION
# Enable Swift
enable_service s-proxy
enable_service s-object
enable_service s-container
enable_service s-account
# Disable Nova Network and enable Neutron
disable_service n-net
enable_service q-svc
enable_service q-agt
enable_service q-dhcp
enable_service q-l3
enable_service q-meta
enable_service q-flavors
# Disable Neutron metering
disable_service q-metering
# Enable LBaaS V1
#enable_service q-lbaas
# Enable FWaaS
enable_service q-fwaas
# Enable LBaaS v2
enable_plugin neutron-lbaas https://git.openstack.org/openstack/neutron-lbaas stable/\$OPENSTACK_VERSION
#enable_plugin octavia https://git.openstack.org/openstack/octavia stable/\$OPENSTACK_VERSION
enable_plugin octavia https://git.openstack.org/openstack/octavia
enable_service q-lbaasv2
enable_service octavia
enable_service o-cw
enable_service o-hm
enable_service o-hk
enable_service o-api
# Octavia
OCTAVIA_AUTH_VERSION=3
# Enable Trove
#enable_plugin trove git://git.openstack.org/openstack/trove.git stable/\$OPENSTACK_VERSION
#enable_service trove,tr-api,tr-tmgr,tr-cond
# Disable Temptest
disable_service tempest
# Disable Horizon
disable_service horizon
# Disable Keystone v2
ENABLE_IDENTITY_V2=False
# Enable SSL/tls
#enable_service tls-proxy
#USE_SSL=True
# Enable Ceilometer
#enable_service ceilometer-acompute
#enable_service ceilometer-acentral
#enable_service ceilometer-anotification
#enable_service ceilometer-collector
#enable_service ceilometer-alarm-evaluator
#enable_service ceilometer-alarm-notifier
#enable_service ceilometer-api
# Enable Zaqar
#enable_plugin zaqar https://github.com/openstack/zaqar
#enable_service zaqar-server
# Automatically download and register a VM image that Heat can launch
# For more information on Heat and DevStack see
# http://docs.openstack.org/developer/heat/getting_started/on_devstack.html
#IMAGE_URLS+=",http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2"
#IMAGE_URLS+=",https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img"
# Logging
LOGDAYS=1
LOGFILE=/opt/stack/logs/stack.sh.log
LOGDIR=/opt/stack/logs
[[post-config|\$OCTAVIA_CONF]]
[default]
debug = true
verbose = true
[keystone_authtoken]
auth_uri = http://localhost:5000/v3
auth_url = http://localhost:35357/v3
user_domain_id = default
project_name = default
auth_type = password
[keystone_authtoken_v3]
admin_user_domain = default
admin_project_domain = default
[[post-config|\$NEUTRON_CONF]]
[service_auth]
auth_version = 3
auth_uri = http://localhost:5000/v3
auth_url = http://localhost:35357/v3
admin_user_domain = default
admin_project_domain = default
[[post-config|\$NEUTRON_LBAAS_CONF]]
[service_auth]
auth_version = 3
auth_uri = http://localhost:5000/v3
auth_url = http://localhost:35357/v3
admin_user_domain = default
admin_project_domain = default
EOF
./stack.sh
# Patch openrc
cat >> openrc <<EOF
if [ "\$OS_IDENTITY_API_VERSION" = "3" ]; then
export OS_DOMAIN_NAME=\${OS_DOMAIN_NAME:-"default"}
fi
EOF
# Prep the testing environment by creating the required testing resources and environment variables
source openrc admin
wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
glance image-create --name CirrOS --disk-format qcow2 --container-format bare < cirros-0.3.4-x86_64-disk.img
nova flavor-create m1.acctest 99 512 5 1 --ephemeral 10
nova flavor-create m1.resize 98 512 6 1 --ephemeral 10
_NETWORK_ID=$(nova net-list | grep private | awk -F\| '{print $2}' | tr -d ' ')
_EXTGW_ID=$(nova net-list | grep public | awk -F\| '{print $2}' | tr -d ' ')
_IMAGE_ID=$(nova image-list | grep CirrOS | awk -F\| '{print $2}' | tr -d ' ' | head -1)
echo export OS_IMAGE_NAME="cirros-0.3.4-x86_64-uec" >> openrc
echo export OS_IMAGE_ID="$_IMAGE_ID" >> openrc
echo export OS_NETWORK_ID=$_NETWORK_ID >> openrc
echo export OS_EXTGW_ID=$_EXTGW_ID >> openrc
echo export OS_POOL_NAME="public" >> openrc
echo export OS_FLAVOR_ID=99 >> openrc
echo export OS_FLAVOR_ID_RESIZE=98 >> openrc
source openrc demo

View File

@ -1,25 +0,0 @@
#!/bin/bash
#
# This script helps new contributors set up their local workstation for
# gophercloud development and contributions.
# Create the environment
export GOPATH=$HOME/go/gophercloud
mkdir -p $GOPATH
# Download gophercloud into that environment
go get github.com/gophercloud/gophercloud
cd $GOPATH/src/github.com/gophercloud/gophercloud
git checkout master
# Write out the env.sh convenience file.
cd $GOPATH
cat <<EOF >env.sh
#!/bin/bash
export GOPATH=$(pwd)
export GOPHERCLOUD=$GOPATH/src/github.com/gophercloud/gophercloud
EOF
chmod a+x env.sh
# Make changes immediately available as a convenience.
. ./env.sh

View File

@ -1,5 +0,0 @@
#!/bin/bash
#
# Test script to be invoked by Travis.
exec script/unittest -v

View File

@ -1,9 +0,0 @@
#!/bin/bash
n=1
for testpkg in $(go list ./testing ./.../testing); do
covpkg="${testpkg/"/testing"/}"
go test -covermode count -coverprofile "testing_"$n.coverprofile -coverpkg $covpkg $testpkg 2>/dev/null
n=$((n+1))
done
gocovmerge `ls *.coverprofile` > cover.out
rm *.coverprofile

View File

@ -1,5 +0,0 @@
#!/bin/bash
#
# Run all the tests.
exec go test -tags 'acceptance fixtures' ./... $@

View File

@ -1,5 +0,0 @@
#!/bin/bash
#
# Run the unit tests.
exec go test ./testing ./.../testing $@

View File

@ -1,17 +0,0 @@
package client
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/testhelper"
)
// Fake token to use.
const TokenID = "cbc36478b0bd8e67e89469c7749d4127"
// ServiceClient returns a generic service client for use in tests.
func ServiceClient() *gophercloud.ServiceClient {
return &gophercloud.ServiceClient{
ProviderClient: &gophercloud.ProviderClient{TokenID: TokenID},
Endpoint: testhelper.Endpoint(),
}
}

View File

@ -1,348 +0,0 @@
package testhelper
import (
"bytes"
"encoding/json"
"fmt"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"
)
const (
logBodyFmt = "\033[1;31m%s %s\033[0m"
greenCode = "\033[0m\033[1;32m"
yellowCode = "\033[0m\033[1;33m"
resetCode = "\033[0m\033[1;31m"
)
func prefix(depth int) string {
_, file, line, _ := runtime.Caller(depth)
return fmt.Sprintf("Failure in %s, line %d:", filepath.Base(file), line)
}
func green(str interface{}) string {
return fmt.Sprintf("%s%#v%s", greenCode, str, resetCode)
}
func yellow(str interface{}) string {
return fmt.Sprintf("%s%#v%s", yellowCode, str, resetCode)
}
func logFatal(t *testing.T, str string) {
t.Fatalf(logBodyFmt, prefix(3), str)
}
func logError(t *testing.T, str string) {
t.Errorf(logBodyFmt, prefix(3), str)
}
type diffLogger func([]string, interface{}, interface{})
type visit struct {
a1 uintptr
a2 uintptr
typ reflect.Type
}
// Recursively visits the structures of "expected" and "actual". The diffLogger function will be
// invoked with each different value encountered, including the reference path that was followed
// to get there.
func deepDiffEqual(expected, actual reflect.Value, visited map[visit]bool, path []string, logDifference diffLogger) {
defer func() {
// Fall back to the regular reflect.DeepEquals function.
if r := recover(); r != nil {
var e, a interface{}
if expected.IsValid() {
e = expected.Interface()
}
if actual.IsValid() {
a = actual.Interface()
}
if !reflect.DeepEqual(e, a) {
logDifference(path, e, a)
}
}
}()
if !expected.IsValid() && actual.IsValid() {
logDifference(path, nil, actual.Interface())
return
}
if expected.IsValid() && !actual.IsValid() {
logDifference(path, expected.Interface(), nil)
return
}
if !expected.IsValid() && !actual.IsValid() {
return
}
hard := func(k reflect.Kind) bool {
switch k {
case reflect.Array, reflect.Map, reflect.Slice, reflect.Struct:
return true
}
return false
}
if expected.CanAddr() && actual.CanAddr() && hard(expected.Kind()) {
addr1 := expected.UnsafeAddr()
addr2 := actual.UnsafeAddr()
if addr1 > addr2 {
addr1, addr2 = addr2, addr1
}
if addr1 == addr2 {
// References are identical. We can short-circuit
return
}
typ := expected.Type()
v := visit{addr1, addr2, typ}
if visited[v] {
// Already visited.
return
}
// Remember this visit for later.
visited[v] = true
}
switch expected.Kind() {
case reflect.Array:
for i := 0; i < expected.Len(); i++ {
hop := append(path, fmt.Sprintf("[%d]", i))
deepDiffEqual(expected.Index(i), actual.Index(i), visited, hop, logDifference)
}
return
case reflect.Slice:
if expected.IsNil() != actual.IsNil() {
logDifference(path, expected.Interface(), actual.Interface())
return
}
if expected.Len() == actual.Len() && expected.Pointer() == actual.Pointer() {
return
}
for i := 0; i < expected.Len(); i++ {
hop := append(path, fmt.Sprintf("[%d]", i))
deepDiffEqual(expected.Index(i), actual.Index(i), visited, hop, logDifference)
}
return
case reflect.Interface:
if expected.IsNil() != actual.IsNil() {
logDifference(path, expected.Interface(), actual.Interface())
return
}
deepDiffEqual(expected.Elem(), actual.Elem(), visited, path, logDifference)
return
case reflect.Ptr:
deepDiffEqual(expected.Elem(), actual.Elem(), visited, path, logDifference)
return
case reflect.Struct:
for i, n := 0, expected.NumField(); i < n; i++ {
field := expected.Type().Field(i)
hop := append(path, "."+field.Name)
deepDiffEqual(expected.Field(i), actual.Field(i), visited, hop, logDifference)
}
return
case reflect.Map:
if expected.IsNil() != actual.IsNil() {
logDifference(path, expected.Interface(), actual.Interface())
return
}
if expected.Len() == actual.Len() && expected.Pointer() == actual.Pointer() {
return
}
var keys []reflect.Value
if expected.Len() >= actual.Len() {
keys = expected.MapKeys()
} else {
keys = actual.MapKeys()
}
for _, k := range keys {
expectedValue := expected.MapIndex(k)
actualValue := expected.MapIndex(k)
if !expectedValue.IsValid() {
logDifference(path, nil, actual.Interface())
return
}
if !actualValue.IsValid() {
logDifference(path, expected.Interface(), nil)
return
}
hop := append(path, fmt.Sprintf("[%v]", k))
deepDiffEqual(expectedValue, actualValue, visited, hop, logDifference)
}
return
case reflect.Func:
if expected.IsNil() != actual.IsNil() {
logDifference(path, expected.Interface(), actual.Interface())
}
return
default:
if expected.Interface() != actual.Interface() {
logDifference(path, expected.Interface(), actual.Interface())
}
}
}
func deepDiff(expected, actual interface{}, logDifference diffLogger) {
if expected == nil || actual == nil {
logDifference([]string{}, expected, actual)
return
}
expectedValue := reflect.ValueOf(expected)
actualValue := reflect.ValueOf(actual)
if expectedValue.Type() != actualValue.Type() {
logDifference([]string{}, expected, actual)
return
}
deepDiffEqual(expectedValue, actualValue, map[visit]bool{}, []string{}, logDifference)
}
// AssertEquals compares two arbitrary values and performs a comparison. If the
// comparison fails, a fatal error is raised that will fail the test
func AssertEquals(t *testing.T, expected, actual interface{}) {
if expected != actual {
logFatal(t, fmt.Sprintf("expected %s but got %s", green(expected), yellow(actual)))
}
}
// CheckEquals is similar to AssertEquals, except with a non-fatal error
func CheckEquals(t *testing.T, expected, actual interface{}) {
if expected != actual {
logError(t, fmt.Sprintf("expected %s but got %s", green(expected), yellow(actual)))
}
}
// AssertDeepEquals - like Equals - performs a comparison - but on more complex
// structures that requires deeper inspection
func AssertDeepEquals(t *testing.T, expected, actual interface{}) {
pre := prefix(2)
differed := false
deepDiff(expected, actual, func(path []string, expected, actual interface{}) {
differed = true
t.Errorf("\033[1;31m%sat %s expected %s, but got %s\033[0m",
pre,
strings.Join(path, ""),
green(expected),
yellow(actual))
})
if differed {
logFatal(t, "The structures were different.")
}
}
// CheckDeepEquals is similar to AssertDeepEquals, except with a non-fatal error
func CheckDeepEquals(t *testing.T, expected, actual interface{}) {
pre := prefix(2)
deepDiff(expected, actual, func(path []string, expected, actual interface{}) {
t.Errorf("\033[1;31m%s at %s expected %s, but got %s\033[0m",
pre,
strings.Join(path, ""),
green(expected),
yellow(actual))
})
}
func isByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) bool {
return bytes.Equal(expectedBytes, actualBytes)
}
// AssertByteArrayEquals a convenience function for checking whether two byte arrays are equal
func AssertByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) {
if !isByteArrayEquals(t, expectedBytes, actualBytes) {
logFatal(t, "The bytes differed.")
}
}
// CheckByteArrayEquals a convenience function for silent checking whether two byte arrays are equal
func CheckByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) {
if !isByteArrayEquals(t, expectedBytes, actualBytes) {
logError(t, "The bytes differed.")
}
}
// isJSONEquals is a utility function that implements JSON comparison for AssertJSONEquals and
// CheckJSONEquals.
func isJSONEquals(t *testing.T, expectedJSON string, actual interface{}) bool {
var parsedExpected, parsedActual interface{}
err := json.Unmarshal([]byte(expectedJSON), &parsedExpected)
if err != nil {
t.Errorf("Unable to parse expected value as JSON: %v", err)
return false
}
jsonActual, err := json.Marshal(actual)
AssertNoErr(t, err)
err = json.Unmarshal(jsonActual, &parsedActual)
AssertNoErr(t, err)
if !reflect.DeepEqual(parsedExpected, parsedActual) {
prettyExpected, err := json.MarshalIndent(parsedExpected, "", " ")
if err != nil {
t.Logf("Unable to pretty-print expected JSON: %v\n%s", err, expectedJSON)
} else {
// We can't use green() here because %#v prints prettyExpected as a byte array literal, which
// is... unhelpful. Converting it to a string first leaves "\n" uninterpreted for some reason.
t.Logf("Expected JSON:\n%s%s%s", greenCode, prettyExpected, resetCode)
}
prettyActual, err := json.MarshalIndent(actual, "", " ")
if err != nil {
t.Logf("Unable to pretty-print actual JSON: %v\n%#v", err, actual)
} else {
// We can't use yellow() for the same reason.
t.Logf("Actual JSON:\n%s%s%s", yellowCode, prettyActual, resetCode)
}
return false
}
return true
}
// AssertJSONEquals serializes a value as JSON, parses an expected string as JSON, and ensures that
// both are consistent. If they aren't, the expected and actual structures are pretty-printed and
// shown for comparison.
//
// This is useful for comparing structures that are built as nested map[string]interface{} values,
// which are a pain to construct as literals.
func AssertJSONEquals(t *testing.T, expectedJSON string, actual interface{}) {
if !isJSONEquals(t, expectedJSON, actual) {
logFatal(t, "The generated JSON structure differed.")
}
}
// CheckJSONEquals is similar to AssertJSONEquals, but nonfatal.
func CheckJSONEquals(t *testing.T, expectedJSON string, actual interface{}) {
if !isJSONEquals(t, expectedJSON, actual) {
logError(t, "The generated JSON structure differed.")
}
}
// AssertNoErr is a convenience function for checking whether an error value is
// an actual error
func AssertNoErr(t *testing.T, e error) {
if e != nil {
logFatal(t, fmt.Sprintf("unexpected error %s", yellow(e.Error())))
}
}
// CheckNoErr is similar to AssertNoErr, except with a non-fatal error
func CheckNoErr(t *testing.T, e error) {
if e != nil {
logError(t, fmt.Sprintf("unexpected error %s", yellow(e.Error())))
}
}

View File

@ -1,4 +0,0 @@
/*
Package testhelper container methods that are useful for writing unit tests.
*/
package testhelper

View File

@ -1,91 +0,0 @@
package testhelper
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"testing"
)
var (
// Mux is a multiplexer that can be used to register handlers.
Mux *http.ServeMux
// Server is an in-memory HTTP server for testing.
Server *httptest.Server
)
// SetupHTTP prepares the Mux and Server.
func SetupHTTP() {
Mux = http.NewServeMux()
Server = httptest.NewServer(Mux)
}
// TeardownHTTP releases HTTP-related resources.
func TeardownHTTP() {
Server.Close()
}
// Endpoint returns a fake endpoint that will actually target the Mux.
func Endpoint() string {
return Server.URL + "/"
}
// TestFormValues ensures that all the URL parameters given to the http.Request are the same as values.
func TestFormValues(t *testing.T, r *http.Request, values map[string]string) {
want := url.Values{}
for k, v := range values {
want.Add(k, v)
}
r.ParseForm()
if !reflect.DeepEqual(want, r.Form) {
t.Errorf("Request parameters = %v, want %v", r.Form, want)
}
}
// TestMethod checks that the Request has the expected method (e.g. GET, POST).
func TestMethod(t *testing.T, r *http.Request, expected string) {
if expected != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, expected)
}
}
// TestHeader checks that the header on the http.Request matches the expected value.
func TestHeader(t *testing.T, r *http.Request, header string, expected string) {
if actual := r.Header.Get(header); expected != actual {
t.Errorf("Header %s = %s, expected %s", header, actual, expected)
}
}
// TestBody verifies that the request body matches an expected body.
func TestBody(t *testing.T, r *http.Request, expected string) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("Unable to read body: %v", err)
}
str := string(b)
if expected != str {
t.Errorf("Body = %s, expected %s", str, expected)
}
}
// TestJSONRequest verifies that the JSON payload of a request matches an expected structure, without asserting things about
// whitespace or ordering.
func TestJSONRequest(t *testing.T, r *http.Request, expected string) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("Unable to read request body: %v", err)
}
var actualJSON interface{}
err = json.Unmarshal(b, &actualJSON)
if err != nil {
t.Errorf("Unable to parse request body as JSON: %v", err)
}
CheckJSONEquals(t, expected, actualJSON)
}

199
vendor/vendor.json vendored
View File

@ -350,6 +350,102 @@
"revision": "6f45313302b9c56850fc17f99e40caebce98c716",
"revisionTime": "2015-01-27T13:39:51Z"
},
{
"checksumSHA1": "DkbpYqirk9i+2YDR5Ujzpot/oAg=",
"path": "github.com/gophercloud/gophercloud",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "S3zTth9INyj1RfyHkQEvJAvRWvw=",
"path": "github.com/gophercloud/gophercloud/openstack",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "Au6MAsI90lewLByg9n+Yjtdqdh8=",
"path": "github.com/gophercloud/gophercloud/openstack/common/extensions",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "4XWDCGMYqipwJymi9xJo9UffD7g=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "pUlKsepGmWDd4PqPaK4W85pHsRU=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "RWwUliHD65cWApdEo4ckOcPSArg=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "qBpGbX7LQMPATdO8XyQmU7IXDiI=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "a9xDFPigDjHlPlthknKlBduGvKY=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "UGeqrw3KdPNRwDxl315MAYyy/uY=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/images",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "8rOLNDSqwz/DSKL1BoPqjtWSWAE=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/servers",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "1sVqsZBZBNhDXLY9XzjMkcOkcbg=",
"path": "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "q1VGeltZl57OidZ5UDxbMsnyV2g=",
"path": "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "6M6ofb8ri5G+sZ8OiExLi7irdx8=",
"path": "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "Eo+cKV/XzaB5TyxK5ZKWYxPqGWY=",
"path": "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "TDOZnaS0TO0NirpxV1QwPerAQTY=",
"path": "github.com/gophercloud/gophercloud/openstack/utils",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "pmpLcbUZ+EgLUmTbzMtGRq3haOU=",
"path": "github.com/gophercloud/gophercloud/pagination",
"revision": "d5eda9707e146108e4d424062b602fd97a71c2e6",
"revisionTime": "2016-11-14T18:28:31Z"
},
{
"checksumSHA1": "FUiF2WLrih0JdHsUTMMDz3DRokw=",
"comment": "20141209094003-92-g95fa852",
@ -588,109 +684,6 @@
"path": "github.com/pmezard/go-difflib/difflib",
"revision": "792786c7400a136282c1664665ae0a8db921c6c2"
},
{
"checksumSHA1": "reF91HBsVZuUHce8Rxco6k6Bfbc=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "KgPqSv4WKquMdM3Y0FxKIfqf/tw=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack",
"revision": "69cc33768d3318e48fa47a216722d2737e84158b",
"revisionTime": "2016-04-06T18:51:52Z"
},
{
"checksumSHA1": "/K+RHJM5BFeg+3DYsR3WKPh7oVo=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/common/extensions",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "PPwPUj78EdIs+24vRMlThGWa6kw=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "kCkaqHFDBuZem57TEmfCpCNeUWs=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "A8CBSjxtNeXBtM3M51qqs5FMVNE=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "G3pxSBafMhqdqvuDPsctv74nI2M=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/startstop",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "C2K3kYQgwa65cVRvWrNZACQFX7Q=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/flavors",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "59nKYOu3eBZn82AWlZUGLwzieeM=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/images",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "+GkNX1ZNVOdbevUkfJUt/xGPZU0=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/servers",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "kBNUmTmGZgMc7RA8b/MfF8mNLrw=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/identity/v2/tenants",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "QWhBGvvt47Wpw4qf3bt/rVgXdyw=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/identity/v2/tokens",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "MKnoVPcRvTrooZtNQwOnJy0bglc=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/identity/v3/tokens",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "e4ussrqujJHizWbdBaLjIpWYmgY=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/openstack/utils",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "zNrhzobVrzrPD3NF8K0D8U/J4UM=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/pagination",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "U2yzK8GFNeHZqcoeotcHmK57lAI=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/testhelper",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "fXtvTbQBML8QLu/qpD9sAt53J00=",
"comment": "v1.0.0-810-g53d1dc4",
"path": "github.com/rackspace/gophercloud/testhelper/client",
"revision": "53d1dc4400e1ebcd37a0e01d8c1fe2f4db3b99d2"
},
{
"checksumSHA1": "TvF3ym5sZVNqGlUOS9HgOIl/sZM=",
"path": "github.com/satori/go.uuid",