From 9871b73590e114360405cd142dca7a924318816e Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Thu, 23 Mar 2017 14:44:07 -0500
Subject: [PATCH] Convert examples into proper stand-alone commands

Change-Id: I334dd55fb5076a4d3f3b42770681ef6111ccc90f
---
 .../authentication.go}                                      | 3 ++-
 examples/config.json.dist                                   | 2 +-
 examples/{30-image-v1.go => image/image.go}                 | 5 +++--
 .../{10-objectstore.go => objectstorage/objectstorage.go}   | 3 ++-
 examples/run-all.sh                                         | 6 +++---
 examples/{ => setup}/setup.go                               | 4 ++--
 examples/{40-volume-v2.go => volume/volume.go}              | 5 +++--
 7 files changed, 16 insertions(+), 12 deletions(-)
 rename examples/{00-authentication.go => authentication/authentication.go} (96%)
 rename examples/{30-image-v1.go => image/image.go} (95%)
 rename examples/{10-objectstore.go => objectstorage/objectstorage.go} (98%)
 rename examples/{ => setup}/setup.go (97%)
 rename examples/{40-volume-v2.go => volume/volume.go} (95%)

diff --git a/examples/00-authentication.go b/examples/authentication/authentication.go
similarity index 96%
rename from examples/00-authentication.go
rename to examples/authentication/authentication.go
index 195e7f8..8a5368b 100644
--- a/examples/00-authentication.go
+++ b/examples/authentication/authentication.go
@@ -22,11 +22,12 @@ import (
 	"time"
 
 	"git.openstack.org/openstack/golang-client/openstack"
+	"git.openstack.org/openstack/golang-client/examples/setup"
 )
 
 // Authentication examples.
 func main() {
-	config := getConfig()
+	config := setup.GetConfig()
 
 	// Authenticate with just a username and password. The returned token is
 	// unscoped to a tenant.
diff --git a/examples/config.json.dist b/examples/config.json.dist
index c4aae1d..a4255d0 100644
--- a/examples/config.json.dist
+++ b/examples/config.json.dist
@@ -4,6 +4,6 @@
 	"Password": "",
 	"ProjectID": "",
 	"ProjectName": "",
- 	"Container": "I♡HPHelion"
+	"Container": ""
 	"ImageRegion": ""
 }
\ No newline at end of file
diff --git a/examples/30-image-v1.go b/examples/image/image.go
similarity index 95%
rename from examples/30-image-v1.go
rename to examples/image/image.go
index 9d067c1..fdd540c 100644
--- a/examples/30-image-v1.go
+++ b/examples/image/image.go
@@ -23,11 +23,12 @@ import (
 
 	"git.openstack.org/openstack/golang-client/image/v1"
 	"git.openstack.org/openstack/golang-client/openstack"
+	"git.openstack.org/openstack/golang-client/examples/setup"
 )
 
 // Image examples.
 func main() {
-	config := getConfig()
+	config := setup.GetConfig()
 
 	// Authenticate with a username, password, tenant id.
 	creds := openstack.AuthOpts{
@@ -58,7 +59,7 @@ func main() {
 		panic(panicString)
 	}
 
-	imageService := image.Service{
+	imageService := v1.Service{
 		Session: *sess,
 		Client:  *http.DefaultClient,
 		URL:     url + "/v1", // We're forcing Image v1 for now
diff --git a/examples/10-objectstore.go b/examples/objectstorage/objectstorage.go
similarity index 98%
rename from examples/10-objectstore.go
rename to examples/objectstorage/objectstorage.go
index 10c4daf..441ca72 100644
--- a/examples/10-objectstore.go
+++ b/examples/objectstorage/objectstorage.go
@@ -26,10 +26,11 @@ import (
 
 	"git.openstack.org/openstack/golang-client/objectstorage/v1"
 	"git.openstack.org/openstack/golang-client/openstack"
+	"git.openstack.org/openstack/golang-client/examples/setup"
 )
 
 func main() {
-	config := getConfig()
+	config := setup.GetConfig()
 
 	// Before working with object storage we need to authenticate with a project
 	// that has active object storage.
diff --git a/examples/run-all.sh b/examples/run-all.sh
index 429c07e..0b27996 100755
--- a/examples/run-all.sh
+++ b/examples/run-all.sh
@@ -22,9 +22,9 @@ echo "Executing the examples in: $DIR"
 cd $DIR
 
 # Run all the tests.
-for T in $(ls -1 [0-9][0-9]*.go); do
-	if ! [ -x $T ]; then
-		CMD="go run $T setup.go"
+for T in $(find . -type d \! -path \*setup -name [a-z]\*); do
+	if [ -d $T ]; then
+		CMD="go run $T/$T.go"
 		echo "$CMD ..."
 		if ! $CMD ; then
 			echo "Error executing example $T."
diff --git a/examples/setup.go b/examples/setup/setup.go
similarity index 97%
rename from examples/setup.go
rename to examples/setup/setup.go
index 7e0a816..271516f 100644
--- a/examples/setup.go
+++ b/examples/setup/setup.go
@@ -17,7 +17,7 @@
 // The acceptance package is a set of acceptance tests showcasing how the
 // contents of the package are meant to be used. This is setup in a similar
 // manner to a consuming application.
-package main
+package setup
 
 import (
 	"encoding/json"
@@ -41,7 +41,7 @@ type testconfig struct {
 }
 
 // getConfig provides access to credentials in other tests and examples.
-func getConfig() *testconfig {
+func GetConfig() *testconfig {
 	config := &testconfig{}
 	userJSON, err := ioutil.ReadFile("config.json")
 	if err != nil {
diff --git a/examples/40-volume-v2.go b/examples/volume/volume.go
similarity index 95%
rename from examples/40-volume-v2.go
rename to examples/volume/volume.go
index 14a4a47..d6e079e 100644
--- a/examples/40-volume-v2.go
+++ b/examples/volume/volume.go
@@ -23,11 +23,12 @@ import (
 
 	"git.openstack.org/openstack/golang-client/openstack"
 	"git.openstack.org/openstack/golang-client/volume/v2"
+	"git.openstack.org/openstack/golang-client/examples/setup"
 )
 
 // Volume examples.
 func main() {
-	config := getConfig()
+	config := setup.GetConfig()
 
 	// Authenticate with a username, password, tenant id.
 	creds := openstack.AuthOpts{
@@ -58,7 +59,7 @@ func main() {
 		panic(panicString)
 	}
 
-	volumeService := volume.Service{
+	volumeService := v2.Service{
 		Session: *sess,
 		Client:  *http.DefaultClient,
 		URL:     url, // We're forcing Volume v2 for now