Class: Fastlane::FirebaseTestLab::FirebaseTestLabService
- Inherits:
-
Object
- Object
- Fastlane::FirebaseTestLab::FirebaseTestLabService
- Defined in:
- lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_default_bucket(gcp_project) ⇒ Object
- #get_execution_steps(gcp_project, history_id, execution_id) ⇒ Object
- #get_matrix_results(gcp_project, matrix_id) ⇒ Object
- #init_default_bucket(gcp_project) ⇒ Object
-
#initialize(credential) ⇒ FirebaseTestLabService
constructor
A new instance of FirebaseTestLabService.
- #start_job(gcp_project, app_path, result_path, devices, timeout_sec) ⇒ Object
Constructor Details
#initialize(credential) ⇒ FirebaseTestLabService
Returns a new instance of FirebaseTestLabService.
31 32 33 34 |
# File 'lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb', line 31 def initialize(credential) @auth = credential.get_google_credential(TESTLAB_OAUTH_SCOPES) @default_bucket = nil end |
Class Method Details
.map_device_to_proto(device) ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb', line 192 def self.map_device_to_proto(device) { iosModelId: device[:ios_model_id], iosVersionId: device[:ios_version_id], locale: device[:locale], orientation: device[:orientation] } end |
Instance Method Details
#get_default_bucket(gcp_project) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb', line 50 def get_default_bucket(gcp_project) return @default_bucket unless @default_bucket.nil? init_default_bucket(gcp_project) conn = Faraday.new(APIARY_ENDPOINT) begin resp = conn.get(TOOLRESULTS_GET_SETTINGS_API_V3.gsub("{project}", gcp_project)) do |req| req.headers = @auth.apply(req.headers) req..timeout = 15 req..open_timeout = 5 end rescue Faraday::Error => ex UI.("Network error when obtaining Firebase Test Lab default GCS bucket, " \ "type: #{ex.class}, message: #{ex.}") end if resp.status != 200 FastlaneCore::UI.error("Failed to obtain default bucket for Firebase Test Lab.") summarized_error = ErrorHelper.summarize_google_error(resp.body) if summarized_error.include?("Not Authorized for project") FastlaneCore::UI.error("Please make sure that the account associated with your Google credential is the " \ "project editor or owner. You can do this at the Google Developer Console " \ "https://console.cloud.google.com/iam-admin/iam?project=#{gcp_project}") end FastlaneCore::UI.(summarized_error) return nil else response_json = JSON.parse(resp.body) @default_bucket = response_json["defaultBucket"] return @default_bucket end end |
#get_execution_steps(gcp_project, history_id, execution_id) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb', line 168 def get_execution_steps(gcp_project, history_id, execution_id) conn = Faraday.new(APIARY_ENDPOINT) url = TOOLRESULTS_LIST_EXECUTION_STEP_API_V3 .gsub("{project}", gcp_project) .gsub("{history_id}", history_id) .gsub("{execution_id}", execution_id) begin resp = conn.get(url) do |req| req.headers = @auth.apply(req.headers) req..timeout = 15 req..open_timeout = 5 end rescue Faraday::Error => ex UI.("Failed to obtain the metadata of test artifacts, " \ "type: #{ex.class}, message: #{ex.}") end if resp.status != 200 FastlaneCore::UI.error("Failed to obtain the metadata of test artifacts.") FastlaneCore::UI.(ErrorHelper.summarize_google_error(resp.body)) end return JSON.parse(resp.body) end |
#get_matrix_results(gcp_project, matrix_id) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb', line 142 def get_matrix_results(gcp_project, matrix_id) url = FTL_RESULTS_API .gsub("{project}", gcp_project) .gsub("{matrix}", matrix_id) conn = Faraday.new(FIREBASE_TEST_LAB_ENDPOINT) begin resp = conn.get(url) do |req| req.headers = @auth.apply(req.headers) req..timeout = 15 req..open_timeout = 5 end rescue Faraday::Error => ex UI.("Network error when attempting to get test results, " \ "type: #{ex.class}, message: #{ex.}") end if resp.status != 200 FastlaneCore::UI.error("Failed to obtain test results.") FastlaneCore::UI.(ErrorHelper.summarize_google_error(resp.body)) return nil else return JSON.parse(resp.body) end end |
#init_default_bucket(gcp_project) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb', line 36 def init_default_bucket(gcp_project) conn = Faraday.new(APIARY_ENDPOINT) begin conn.post(TOOLRESULTS_INITIALIZE_SETTINGS_API_V3.gsub("{project}", gcp_project)) do |req| req.headers = @auth.apply(req.headers) req..timeout = 15 req..open_timeout = 5 end rescue Faraday::Error => ex UI.("Network error when initializing Firebase Test Lab, " \ "type: #{ex.class}, message: #{ex.}") end end |
#start_job(gcp_project, app_path, result_path, devices, timeout_sec) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/fastlane/plugin/firebase_test_lab/helper/ftl_service.rb', line 83 def start_job(gcp_project, app_path, result_path, devices, timeout_sec) body = { projectId: gcp_project, testSpecification: { testTimeout: { seconds: timeout_sec }, iosTestSetup: {}, iosXcTest: { testsZip: { gcsPath: app_path } } }, environmentMatrix: { iosDeviceList: { iosDevices: devices.map(&FirebaseTestLabService.method(:map_device_to_proto)) } }, resultStorage: { googleCloudStorage: { gcsPath: result_path } }, clientInfo: { name: PLUGIN_NAME, clientInfoDetails: [ { key: "version", value: VERSION } ] } } conn = Faraday.new(FIREBASE_TEST_LAB_ENDPOINT) begin resp = conn.post(FTL_CREATE_API.gsub("{project}", gcp_project)) do |req| req.headers = @auth.apply(req.headers) req.headers["Content-Type"] = "application/json" req.headers["X-Goog-User-Project"] = gcp_project req.body = body.to_json req..timeout = 15 req..open_timeout = 5 end rescue Faraday::Error => ex UI.("Network error when initializing Firebase Test Lab, " \ "type: #{ex.class}, message: #{ex.}") end if resp.status != 200 FastlaneCore::UI.error("Failed to start Firebase Test Lab jobs.") FastlaneCore::UI.(ErrorHelper.summarize_google_error(resp.body)) else response_json = JSON.parse(resp.body) return response_json["testMatrixId"] end end |