Merge pull request #16 from paulcastro/issue_15

Update unit tests to get creds from environment variables
diff --git a/OpenWhisk.xcodeproj/xcshareddata/xcschemes/OpenWhisk.xcscheme b/OpenWhisk.xcodeproj/xcshareddata/xcschemes/OpenWhisk.xcscheme
index 32961c3..32fffff 100644
--- a/OpenWhisk.xcodeproj/xcshareddata/xcschemes/OpenWhisk.xcscheme
+++ b/OpenWhisk.xcodeproj/xcshareddata/xcschemes/OpenWhisk.xcscheme
@@ -70,6 +70,18 @@
             ReferencedContainer = "container:OpenWhisk.xcodeproj">
          </BuildableReference>
       </MacroExpansion>
+      <EnvironmentVariables>
+         <EnvironmentVariable
+            key = "OPENWHISK_TESTAPISECRET"
+            value = "$OPENWHISK_TESTAPISECRET"
+            isEnabled = "YES">
+         </EnvironmentVariable>
+         <EnvironmentVariable
+            key = "OPENWHISK_TESTAPIKEY"
+            value = "$OPENWHISK_TESTAPIKEY"
+            isEnabled = "YES">
+         </EnvironmentVariable>
+      </EnvironmentVariables>
       <AdditionalOptions>
       </AdditionalOptions>
    </LaunchAction>
diff --git a/OpenWhisk/Config.swift b/OpenWhisk/Config.swift
index a7fa2f7..085a4c5 100644
--- a/OpenWhisk/Config.swift
+++ b/OpenWhisk/Config.swift
@@ -21,6 +21,9 @@
 */
 public class Config {
     
+    static let ApiKeyName = "OPENWHISK_TESTAPIKEY"
+    static let ApiSecretName = "OPENWHISK_TESTAPISECRET"
+    
     public class func getHostAndPath(type type:String) -> String? {
         
         var url: String? = nil
@@ -89,8 +92,8 @@
     public class func getAuthToken() -> (apiKey: String?, apiSecret: String?)? {
         
         let dict = NSProcessInfo.processInfo().environment
-        let key = dict["TESTAPIKEY"]
-        let secret = dict["TESTAPISECRET"]
+        let key = dict[Config.ApiKeyName]
+        let secret = dict[Config.ApiSecretName]
         
         return(key, secret)
     }
diff --git a/OpenWhiskTests/OpenWhiskTests.swift b/OpenWhiskTests/OpenWhiskTests.swift
index 427d06c..a764c04 100644
--- a/OpenWhiskTests/OpenWhiskTests.swift
+++ b/OpenWhiskTests/OpenWhiskTests.swift
@@ -1,18 +1,18 @@
 /*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright 2015-2016 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 import XCTest
 import OpenWhisk
@@ -63,31 +63,31 @@
             
             do {
                 try whisk.invokeAction(name: "date", package: "util", namespace: "whisk.system", parameters: nil, hasResult: true,
-                    callback: {(reply, error) in
-                        
-                        if let error = error {
-                            if case let WhiskError.HTTPError(description, statusCode) = error {
-                                
-                                print("Error: \(description) statusCode: \(statusCode))")
-                                
-                                if statusCode != 401 && statusCode != 404 && statusCode != 408 && statusCode != 500 {
-                                    XCTFail("Error: \(description) statusCode: \(statusCode))")
-                                }
-                                
-                            }
-                        }
-                        
-                        if let reply = reply {
-                            
-                            print("Reply is \(reply)")
-                            XCTAssertNotNil(reply["activationId"])
-                            let id = reply["activationId"] as! String
-                            print("Got id \(id)")
-                        }
-                        
-                        expectation.fulfill()
-                        
-                        
+                                       callback: {(reply, error) in
+                                        
+                                        if let error = error {
+                                            if case let WhiskError.HTTPError(description, statusCode, "default") = error {
+                                                
+                                                print("Error: \(description) statusCode: \(statusCode))")
+                                                
+                                                if statusCode != 401 && statusCode != 404 && statusCode != 408 && statusCode != 500 {
+                                                    XCTFail("Error: \(description) statusCode: \(statusCode))")
+                                                }
+                                                
+                                            }
+                                        }
+                                        
+                                        if let reply = reply {
+                                            
+                                            print("Reply is \(reply)")
+                                            XCTAssertNotNil(reply["activationId"])
+                                            let id = reply["activationId"] as! String
+                                            print("Got id \(id)")
+                                        }
+                                        
+                                        expectation.fulfill()
+                                        
+                                        
                 })
             } catch {
                 print(error)
@@ -120,7 +120,7 @@
                 try whisk.invokeAction(qualifiedName: "/whisk.system/util/date", parameters: nil, hasResult: true, callback: {(reply, error) in
                     
                     if let error = error {
-                        if case let WhiskError.HTTPError(description, statusCode) = error {
+                        if case let WhiskError.HTTPError(description, statusCode, "default") = error {
                             
                             print("Error: \(description) statusCode: \(statusCode))")
                             
@@ -178,7 +178,7 @@
                 try whisk.invokeAction(qualifiedName: "/whisk.system/util/date", parameters: nil, hasResult: true, callback: {(reply, error) in
                     
                     if let error = error {
-                        if case let WhiskError.HTTPError(description, statusCode) = error {
+                        if case let WhiskError.HTTPError(description, statusCode, "default") = error {
                             
                             print("Error: \(description) statusCode: \(statusCode))")
                             
@@ -238,7 +238,7 @@
                 try whisk.invokeAction(qualifiedName: "/whisk.system/util/date", parameters: nil, hasResult: true, callback: {(reply, error) in
                     
                     if let error = error {
-                        if case let WhiskError.HTTPError(description, statusCode) = error {
+                        if case let WhiskError.HTTPError(description, statusCode, "default") = error {
                             
                             print("Error: \(description) statusCode: \(statusCode))")
                             
@@ -297,7 +297,16 @@
                 try whisk.fireTrigger(name: "myTrigger", callback: { (reply, error) in
                     
                     if let error = error {
-                        print("\(error)")
+                        if case let WhiskError.HTTPError(description, statusCode, "default") = error {
+                            
+                            print("Error: \(description) statusCode: \(statusCode))")
+                            
+                            //  actually any of these status codes are probably OK since the API call succeeded
+                            if statusCode != 401 && statusCode != 408 && statusCode != 500 {
+                                XCTFail("Error: \(description) statusCode: \(statusCode))")
+                            }
+                            
+                        }
                     } else if let reply = reply {
                         print("\(reply)")
                     } else {