Remove duplicate code from acceptance tests.
Just cleaning things up here.
diff --git a/acceptance/01-authentication.go b/acceptance/01-authentication.go
index 643ad48..91fc814 100644
--- a/acceptance/01-authentication.go
+++ b/acceptance/01-authentication.go
@@ -1,23 +1,11 @@
package main
import (
- "os"
- "fmt"
"github.com/rackspace/gophercloud"
)
func main() {
- provider := os.Getenv("SDK_PROVIDER")
- username := os.Getenv("SDK_USERNAME")
- password := os.Getenv("SDK_PASSWORD")
-
- if (provider == "") || (username == "") || (password == "") {
- fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
- fmt.Fprintf(os.Stderr, " SDK_PROVIDER=\"%s\"\n", provider)
- fmt.Fprintf(os.Stderr, " SDK_USERNAME=\"%s\"\n", username)
- fmt.Fprintf(os.Stderr, " SDK_PASSWORD=\"%s\"\n", password)
- os.Exit(1)
- }
+ provider, username, password := getCredentials()
_, err := gophercloud.Authenticate(
provider,
diff --git a/acceptance/02-list-servers.go b/acceptance/02-list-servers.go
index acfc802..64ec4f6 100644
--- a/acceptance/02-list-servers.go
+++ b/acceptance/02-list-servers.go
@@ -3,25 +3,13 @@
import (
"fmt"
"github.com/rackspace/gophercloud"
- "os"
"flag"
)
var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
func main() {
- provider := os.Getenv("SDK_PROVIDER")
- username := os.Getenv("SDK_USERNAME")
- password := os.Getenv("SDK_PASSWORD")
-
- if (provider == "") || (username == "") || (password == "") {
- fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
- fmt.Fprintf(os.Stderr, " SDK_PROVIDER=\"%s\"\n", provider)
- fmt.Fprintf(os.Stderr, " SDK_USERNAME=\"%s\"\n", username)
- fmt.Fprintf(os.Stderr, " SDK_PASSWORD=\"%s\"\n", password)
- os.Exit(1)
- }
-
+ provider, username, password := getCredentials()
flag.Parse()
acc, err := gophercloud.Authenticate(
diff --git a/acceptance/03-get-server-details.go b/acceptance/03-get-server-details.go
index 6d826db..bae220f 100644
--- a/acceptance/03-get-server-details.go
+++ b/acceptance/03-get-server-details.go
@@ -4,7 +4,6 @@
"fmt"
"flag"
"github.com/rackspace/gophercloud"
- "os"
)
var id = flag.String("i", "", "Server ID to get info on. Defaults to first server in your account if unspecified.")
@@ -12,18 +11,7 @@
var quiet = flag.Bool("quiet", false, "Run quietly, for acceptance testing. $? non-zero if issue.")
func main() {
- provider := os.Getenv("SDK_PROVIDER")
- username := os.Getenv("SDK_USERNAME")
- password := os.Getenv("SDK_PASSWORD")
-
- if (provider == "") || (username == "") || (password == "") {
- fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
- fmt.Fprintf(os.Stderr, " SDK_PROVIDER=\"%s\"\n", provider)
- fmt.Fprintf(os.Stderr, " SDK_USERNAME=\"%s\"\n", username)
- fmt.Fprintf(os.Stderr, " SDK_PASSWORD=\"%s\"\n", password)
- os.Exit(1)
- }
-
+ provider, username, password := getCredentials()
flag.Parse()
auth, err := gophercloud.Authenticate(
diff --git a/acceptance/libargs.go b/acceptance/libargs.go
new file mode 100644
index 0000000..7b50f46
--- /dev/null
+++ b/acceptance/libargs.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+ "fmt"
+ "os"
+)
+
+// getCredentials will verify existence of needed credential information
+// provided through environment variables. This function will not return
+// if at least one piece of required information is missing.
+func getCredentials() (provider, username, password string) {
+ provider = os.Getenv("SDK_PROVIDER")
+ username = os.Getenv("SDK_USERNAME")
+ password = os.Getenv("SDK_PASSWORD")
+
+ if (provider == "") || (username == "") || (password == "") {
+ fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
+ fmt.Fprintf(os.Stderr, " SDK_PROVIDER=\"%s\"\n", provider)
+ fmt.Fprintf(os.Stderr, " SDK_USERNAME=\"%s\"\n", username)
+ fmt.Fprintf(os.Stderr, " SDK_PASSWORD=\"%s\"\n", password)
+ os.Exit(1)
+ }
+
+ return
+}