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"
"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.

View File

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

View File

@ -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

View File

@ -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.

View File

@ -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."

View File

@ -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 {

View File

@ -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