Преглед изворни кода

Add some testing for a test config with secrets

Matthew Mathias пре 4 година
родитељ
комит
31bf98f517

+ 1 - 0
.gitignore

@@ -10,6 +10,7 @@
 *.xcworkspace/
 project.xcworkspace/
 xcuserdata/
+Samples/Swift/DaysUntilBirthday/Credentials.xcconfig
 
 # CocoaPods
 Pods/

+ 18 - 0
Samples/Swift/DaysUntilBirthday/Credentials.xcconfig

@@ -0,0 +1,18 @@
+//
+// Copyright 2022 Google LLC
+//
+// 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.
+//
+
+EMAIL_SECRET = secret_fake_email@gmail.com
+PASSWORD_SECRET = foobar

+ 15 - 0
Samples/Swift/DaysUntilBirthday/DaysUntilBirthday.xcodeproj/project.pbxproj

@@ -18,6 +18,7 @@
 		7345AD232703D9C30020AFB1 /* UserProfileImageLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7345AD192703D9C30020AFB1 /* UserProfileImageLoader.swift */; };
 		7345AD242703D9C30020AFB1 /* UserProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7345AD1A2703D9C30020AFB1 /* UserProfileView.swift */; };
 		73508EC82811BD9C00ED7FB7 /* DaysUntilBirthdayUITests_iOS_.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73508EC72811BD9C00ED7FB7 /* DaysUntilBirthdayUITests_iOS_.swift */; };
+		73508ED528134C7300ED7FB7 /* Credential.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73508ED428134C7300ED7FB7 /* Credential.swift */; };
 		736F49BA270E05E200580053 /* BirthdayLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736F49B9270E05E200580053 /* BirthdayLoader.swift */; };
 		736F49BC270E102C00580053 /* BirthdayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736F49BB270E102C00580053 /* BirthdayViewModel.swift */; };
 		739FCC46270E467600C92042 /* BirthdayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739FCC45270E467600C92042 /* BirthdayView.swift */; };
@@ -67,6 +68,9 @@
 		7345AD1A2703D9C30020AFB1 /* UserProfileView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserProfileView.swift; sourceTree = "<group>"; };
 		73508EC52811BD9C00ED7FB7 /* DaysUntilBirthdayUITests(iOS).xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "DaysUntilBirthdayUITests(iOS).xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
 		73508EC72811BD9C00ED7FB7 /* DaysUntilBirthdayUITests_iOS_.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaysUntilBirthdayUITests_iOS_.swift; sourceTree = "<group>"; };
+		73508ED2281337AE00ED7FB7 /* DaysUntilBirthdayUITests-iOS--Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "DaysUntilBirthdayUITests-iOS--Info.plist"; sourceTree = SOURCE_ROOT; };
+		73508ED32813391700ED7FB7 /* Credentials.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Credentials.xcconfig; sourceTree = "<group>"; };
+		73508ED428134C7300ED7FB7 /* Credential.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Credential.swift; sourceTree = "<group>"; };
 		736F49B9270E05E200580053 /* BirthdayLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BirthdayLoader.swift; sourceTree = "<group>"; };
 		736F49BB270E102C00580053 /* BirthdayViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BirthdayViewModel.swift; sourceTree = "<group>"; };
 		739FCC45270E467600C92042 /* BirthdayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BirthdayView.swift; sourceTree = "<group>"; };
@@ -114,6 +118,8 @@
 			children = (
 				C1B5D388282AFD3A0068D12B /* README.md */,
 				C14E3C0B280788C600CF05A9 /* Packages */,
+				73508ED32813391700ED7FB7 /* Credentials.xcconfig */,
+				73DB417E2805F9850028B8D3 /* GoogleSignIn-iOS */,
 				7345AD012703D9470020AFB1 /* Shared */,
 				FE7173A927F656AF00910319 /* iOS */,
 				FE71738127ECFAF400910319 /* macOS */,
@@ -163,7 +169,9 @@
 		73508EC62811BD9C00ED7FB7 /* DaysUntilBirthdayUITests(iOS) */ = {
 			isa = PBXGroup;
 			children = (
+				73508ED2281337AE00ED7FB7 /* DaysUntilBirthdayUITests-iOS--Info.plist */,
 				73508EC72811BD9C00ED7FB7 /* DaysUntilBirthdayUITests_iOS_.swift */,
+				73508ED428134C7300ED7FB7 /* Credential.swift */,
 			);
 			path = "DaysUntilBirthdayUITests(iOS)";
 			sourceTree = "<group>";
@@ -401,6 +409,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				73508ED528134C7300ED7FB7 /* Credential.swift in Sources */,
 				73508EC82811BD9C00ED7FB7 /* DaysUntilBirthdayUITests_iOS_.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -557,6 +566,7 @@
 		};
 		7345AD0F2703D9480020AFB1 /* Debug */ = {
 			isa = XCBuildConfiguration;
+			baseConfigurationReference = 73508ED32813391700ED7FB7 /* Credentials.xcconfig */;
 			buildSettings = {
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
@@ -599,11 +609,14 @@
 		};
 		73508ECD2811BD9C00ED7FB7 /* Debug */ = {
 			isa = XCBuildConfiguration;
+			baseConfigurationReference = 73508ED32813391700ED7FB7 /* Credentials.xcconfig */;
 			buildSettings = {
 				CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
 				CODE_SIGN_STYLE = Automatic;
 				CURRENT_PROJECT_VERSION = 1;
 				GENERATE_INFOPLIST_FILE = YES;
+				INFOPLIST_FILE = "DaysUntilBirthdayUITests-iOS--Info.plist";
+				INFOPLIST_KEY_LSApplicationCategoryType = "";
 				IPHONEOS_DEPLOYMENT_TARGET = 15.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
@@ -627,6 +640,8 @@
 				CODE_SIGN_STYLE = Automatic;
 				CURRENT_PROJECT_VERSION = 1;
 				GENERATE_INFOPLIST_FILE = YES;
+				INFOPLIST_FILE = "DaysUntilBirthdayUITests-iOS--Info.plist";
+				INFOPLIST_KEY_LSApplicationCategoryType = "";
 				IPHONEOS_DEPLOYMENT_TARGET = 15.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",

+ 43 - 0
Samples/Swift/DaysUntilBirthday/DaysUntilBirthdayUITests(iOS)/Credential.swift

@@ -0,0 +1,43 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * 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 Foundation
+
+enum Credential: String {
+  private var bundle: Bundle? {
+    return Bundle(identifier: "com.google.DaysUntilBirthdayUITests-iOS-")
+  }
+  private var emailKey: String { return "EMAIL_SECRET" }
+  private var passwordKey: String { return "PASSWORD_SECRET" }
+
+  case email
+  case password
+
+  var rawValue: String {
+    switch self {
+    case .email:
+      guard let email = bundle?.object(forInfoDictionaryKey: emailKey) as? String else {
+        fatalError("Failed to retrieve secret email from UI testing bundle")
+      }
+      return email
+    case .password:
+      guard let password = bundle?.object(forInfoDictionaryKey: passwordKey) as? String else {
+        fatalError("Failed to retrieve secret password from UI testing bundle")
+      }
+      return password
+    }
+  }
+}

+ 5 - 0
Samples/Swift/DaysUntilBirthday/DaysUntilBirthdayUITests(iOS)/DaysUntilBirthdayUITests_iOS_.swift

@@ -37,4 +37,9 @@ class DaysUntilBirthdayUITests_iOS_: XCTestCase {
       return XCTFail("Failed to display prompt")
     }
   }
+
+  func testReadingSecretsFromConfig() {
+    XCTAssertEqual(Credential.email.rawValue, "secret_fake_email@gmail.com")
+    XCTAssertEqual(Credential.password.rawValue, "foobar")
+  }
 }