Convert examples into proper stand-alone commands

Change-Id: I334dd55fb5076a4d3f3b42770681ef6111ccc90f
This commit is contained in:
Dean Troyer 2017-03-23 14:44:07 -05:00
parent 5620f4d381
commit 9871b73590
7 changed files with 16 additions and 12 deletions

View File

@ -22,11 +22,12 @@ import (
"time" "time"
"git.openstack.org/openstack/golang-client/openstack" "git.openstack.org/openstack/golang-client/openstack"
"git.openstack.org/openstack/golang-client/examples/setup"
) )
// Authentication examples. // Authentication examples.
func main() { func main() {
config := getConfig() config := setup.GetConfig()
// Authenticate with just a username and password. The returned token is // Authenticate with just a username and password. The returned token is
// unscoped to a tenant. // unscoped to a tenant.

View File

@ -4,6 +4,6 @@
"Password": "", "Password": "",
"ProjectID": "", "ProjectID": "",
"ProjectName": "", "ProjectName": "",
"Container": "I♡HPHelion" "Container": ""
"ImageRegion": "" "ImageRegion": ""
} }

View File

@ -23,11 +23,12 @@ import (
"git.openstack.org/openstack/golang-client/image/v1" "git.openstack.org/openstack/golang-client/image/v1"
"git.openstack.org/openstack/golang-client/openstack" "git.openstack.org/openstack/golang-client/openstack"
"git.openstack.org/openstack/golang-client/examples/setup"
) )
// Image examples. // Image examples.
func main() { func main() {
config := getConfig() config := setup.GetConfig()
// Authenticate with a username, password, tenant id. // Authenticate with a username, password, tenant id.
creds := openstack.AuthOpts{ creds := openstack.AuthOpts{
@ -58,7 +59,7 @@ func main() {
panic(panicString) panic(panicString)
} }
imageService := image.Service{ imageService := v1.Service{
Session: *sess, Session: *sess,
Client: *http.DefaultClient, Client: *http.DefaultClient,
URL: url + "/v1", // We're forcing Image v1 for now URL: url + "/v1", // We're forcing Image v1 for now

View File

@ -26,10 +26,11 @@ import (
"git.openstack.org/openstack/golang-client/objectstorage/v1" "git.openstack.org/openstack/golang-client/objectstorage/v1"
"git.openstack.org/openstack/golang-client/openstack" "git.openstack.org/openstack/golang-client/openstack"
"git.openstack.org/openstack/golang-client/examples/setup"
) )
func main() { func main() {
config := getConfig() config := setup.GetConfig()
// Before working with object storage we need to authenticate with a project // Before working with object storage we need to authenticate with a project
// that has active object storage. // that has active object storage.

View File

@ -22,9 +22,9 @@ echo "Executing the examples in: $DIR"
cd $DIR cd $DIR
# Run all the tests. # Run all the tests.
for T in $(ls -1 [0-9][0-9]*.go); do for T in $(find . -type d \! -path \*setup -name [a-z]\*); do
if ! [ -x $T ]; then if [ -d $T ]; then
CMD="go run $T setup.go" CMD="go run $T/$T.go"
echo "$CMD ..." echo "$CMD ..."
if ! $CMD ; then if ! $CMD ; then
echo "Error executing example $T." echo "Error executing example $T."

View File

@ -17,7 +17,7 @@
// The acceptance package is a set of acceptance tests showcasing how the // 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 // contents of the package are meant to be used. This is setup in a similar
// manner to a consuming application. // manner to a consuming application.
package main package setup
import ( import (
"encoding/json" "encoding/json"
@ -41,7 +41,7 @@ type testconfig struct {
} }
// getConfig provides access to credentials in other tests and examples. // getConfig provides access to credentials in other tests and examples.
func getConfig() *testconfig { func GetConfig() *testconfig {
config := &testconfig{} config := &testconfig{}
userJSON, err := ioutil.ReadFile("config.json") userJSON, err := ioutil.ReadFile("config.json")
if err != nil { if err != nil {

View File

@ -23,11 +23,12 @@ import (
"git.openstack.org/openstack/golang-client/openstack" "git.openstack.org/openstack/golang-client/openstack"
"git.openstack.org/openstack/golang-client/volume/v2" "git.openstack.org/openstack/golang-client/volume/v2"
"git.openstack.org/openstack/golang-client/examples/setup"
) )
// Volume examples. // Volume examples.
func main() { func main() {
config := getConfig() config := setup.GetConfig()
// Authenticate with a username, password, tenant id. // Authenticate with a username, password, tenant id.
creds := openstack.AuthOpts{ creds := openstack.AuthOpts{
@ -58,7 +59,7 @@ func main() {
panic(panicString) panic(panicString)
} }
volumeService := volume.Service{ volumeService := v2.Service{
Session: *sess, Session: *sess,
Client: *http.DefaultClient, Client: *http.DefaultClient,
URL: url, // We're forcing Volume v2 for now URL: url, // We're forcing Volume v2 for now