|
| 1 | +use std::sync::atomic::{AtomicU8, Ordering}; |
| 2 | + |
| 3 | +use crate::integration::test_utils::AssertCommand; |
| 4 | +use crate::integration::{MockEndpointBuilder, TestManager}; |
| 5 | + |
| 6 | +#[test] |
| 7 | +fn command_upload_dart_symbol_map_missing_capability() { |
| 8 | + // Server does not advertise `dartsymbolmap` capability → command should bail early. |
| 9 | + TestManager::new() |
| 10 | + .mock_endpoint( |
| 11 | + MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/") |
| 12 | + .with_response_file("debug_files/get-chunk-upload.json"), |
| 13 | + ) |
| 14 | + .assert_cmd([ |
| 15 | + "dart-symbol-map", |
| 16 | + "upload", |
| 17 | + "tests/integration/_fixtures/dart_symbol_map/dartsymbolmap.json", |
| 18 | + // Use a fixture with a single Debug ID |
| 19 | + "tests/integration/_fixtures/Sentry.Samples.Console.Basic.pdb", |
| 20 | + ]) |
| 21 | + .with_default_token() |
| 22 | + .run_and_assert(AssertCommand::Failure); |
| 23 | +} |
| 24 | + |
| 25 | +#[test] |
| 26 | +fn command_upload_dart_symbol_map_chunk_upload_flow() { |
| 27 | + // Happy path: server supports dartsymbolmap capability, file needs upload, then assembles to ok. |
| 28 | + let call_count = AtomicU8::new(0); |
| 29 | + |
| 30 | + TestManager::new() |
| 31 | + // Server advertises capability including `dartsymbolmap`. |
| 32 | + .mock_endpoint( |
| 33 | + MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/") |
| 34 | + .with_response_file("dart_symbol_map/get-chunk-upload.json"), |
| 35 | + ) |
| 36 | + // Accept chunk upload requests for the missing chunks; no validation needed here. |
| 37 | + .mock_endpoint(MockEndpointBuilder::new( |
| 38 | + "POST", |
| 39 | + "/api/0/organizations/wat-org/chunk-upload/", |
| 40 | + )) |
| 41 | + // Assemble flow: 1) not_found (missingChunks), 2) created, 3) ok |
| 42 | + .mock_endpoint( |
| 43 | + MockEndpointBuilder::new( |
| 44 | + "POST", |
| 45 | + "/api/0/projects/wat-org/wat-project/files/difs/assemble/", |
| 46 | + ) |
| 47 | + .with_header_matcher("content-type", "application/json") |
| 48 | + .with_response_fn(move |request| { |
| 49 | + let body = request.body().expect("body should be readable"); |
| 50 | + let body_json: serde_json::Value = serde_json::from_slice(body) |
| 51 | + .expect("request body should be valid JSON"); |
| 52 | + |
| 53 | + // The request map has a single entry keyed by checksum; reuse it in responses. |
| 54 | + let (checksum, _obj) = body_json |
| 55 | + .as_object() |
| 56 | + .and_then(|m| m.iter().next()) |
| 57 | + .map(|(k, v)| (k.clone(), v.clone())) |
| 58 | + .expect("assemble request must contain at least one object"); |
| 59 | + |
| 60 | + match call_count.fetch_add(1, Ordering::Relaxed) { |
| 61 | + 0 => format!( |
| 62 | + "{{\"{checksum}\":{{\"state\":\"not_found\",\"missingChunks\":[\"{checksum}\"]}}}}" |
| 63 | + ) |
| 64 | + .into(), |
| 65 | + 1 => format!( |
| 66 | + "{{\"{checksum}\":{{\"state\":\"created\",\"missingChunks\":[]}}}}" |
| 67 | + ) |
| 68 | + .into(), |
| 69 | + 2 => format!( |
| 70 | + "{{\"{checksum}\":{{\"state\":\"ok\",\"detail\":null,\"missingChunks\":[],\"dif\":{{\"id\":\"1\",\"uuid\":\"00000000-0000-0000-0000-000000000000\",\"debugId\":\"00000000-0000-0000-0000-000000000000\",\"objectName\":\"dartsymbolmap.json\",\"cpuName\":\"any\",\"headers\":{{\"Content-Type\":\"application/octet-stream\"}},\"size\":1,\"sha1\":\"{checksum}\",\"dateCreated\":\"1776-07-04T12:00:00.000Z\",\"data\":{{}}}}}}}}" |
| 71 | + ) |
| 72 | + .into(), |
| 73 | + n => panic!( |
| 74 | + "Only 3 calls to the assemble endpoint expected, but there were {}.", |
| 75 | + n + 1 |
| 76 | + ), |
| 77 | + } |
| 78 | + }) |
| 79 | + .expect(3), |
| 80 | + ) |
| 81 | + .assert_cmd([ |
| 82 | + "dart-symbol-map", |
| 83 | + "upload", |
| 84 | + "tests/integration/_fixtures/dart_symbol_map/dartsymbolmap.json", |
| 85 | + // Use a fixture with a single Debug ID (embedded PDB) |
| 86 | + "tests/integration/_fixtures/Sentry.Samples.Console.Basic.pdb", |
| 87 | + ]) |
| 88 | + .with_default_token() |
| 89 | + .run_and_assert(AssertCommand::Success); |
| 90 | +} |
| 91 | + |
| 92 | +#[test] |
| 93 | +fn command_upload_dart_symbol_map_invalid_mapping() { |
| 94 | + // Invalid mapping (odd number of entries) should fail before any HTTP calls. |
| 95 | + TestManager::new() |
| 96 | + .assert_cmd([ |
| 97 | + "dart-symbol-map", |
| 98 | + "upload", |
| 99 | + "tests/integration/_fixtures/dart_symbol_map/dartsymbolmap-invalid.json", |
| 100 | + "tests/integration/_fixtures/Sentry.Samples.Console.Basic.pdb", |
| 101 | + ]) |
| 102 | + .with_default_token() |
| 103 | + .run_and_assert(AssertCommand::Failure); |
| 104 | +} |
0 commit comments