-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathupload_metadata.rs
More file actions
152 lines (143 loc) · 5.86 KB
/
upload_metadata.rs
File metadata and controls
152 lines (143 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
82
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
141
142
143
144
145
146
147
148
149
150
151
152
use serde_json::json;
use super::UploadMetadata;
impl UploadMetadata {
pub fn get_hash(&self) -> String {
let upload_metadata_string = json!(&self).to_string();
sha256::digest(upload_metadata_string)
}
}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use insta::{assert_json_snapshot, assert_snapshot};
use crate::executor::ExecutorName;
use crate::instruments::InstrumentName;
use crate::run_environment::{
GhData, LocalData, RepositoryProvider, RunEnvironment, RunEnvironmentMetadata, RunEvent,
RunPart, Sender,
};
use crate::system::SystemInfo;
use crate::upload::{LATEST_UPLOAD_METADATA_VERSION, Runner, UploadMetadata};
#[test]
fn test_get_metadata_hash() {
let upload_metadata = UploadMetadata {
repository_provider: RepositoryProvider::GitHub,
version: Some(LATEST_UPLOAD_METADATA_VERSION),
tokenless: true,
profile_md5: "jp/k05RKuqP3ERQuIIvx4Q==".into(),
profile_encoding: Some("gzip".into()),
runner: Runner {
name: "codspeed-runner".into(),
version: "2.1.0".into(),
instruments: vec![InstrumentName::MongoDB],
executor: ExecutorName::Valgrind,
system_info: SystemInfo::test(),
},
run_environment: RunEnvironment::GithubActions,
commit_hash: "5bd77cb0da72bef094893ed45fb793ff16ecfbe3".into(),
allow_empty: false,
run_environment_metadata: RunEnvironmentMetadata {
ref_: "refs/pull/29/merge".into(),
head_ref: Some("chore/native-action-runner".into()),
base_ref: Some("main".into()),
owner: "CodSpeedHQ".into(),
repository: "codspeed-node".into(),
event: RunEvent::PullRequest,
gh_data: Some(GhData {
run_id: "7044765741".into(),
job: "codspeed".into(),
}),
sender: Some(Sender {
id: "19605940".into(),
login: "adriencaccia".into(),
}),
gl_data: None,
local_data: None,
repository_root_path: "/home/runner/work/codspeed-node/codspeed-node/".into(),
},
run_part: Some(RunPart {
run_id: "7044765741".into(),
run_part_id: "benchmarks_3.2.2".into(),
job_name: "codspeed".into(),
metadata: BTreeMap::from([
("someKey".into(), "someValue".into()),
("anotherKey".into(), "anotherValue".into()),
]),
}),
};
let hash = upload_metadata.get_hash();
assert_snapshot!(
hash,
// Caution: when changing this value, we need to ensure that
// the related backend snapshot remains the same
@"0afc09ee58a610d400aa6b3fbdddf628608ed2e11aed39585a50abe96e1c9284"
);
assert_json_snapshot!(upload_metadata);
}
#[test]
fn test_get_local_metadata_hash() {
let upload_metadata = UploadMetadata {
repository_provider: RepositoryProvider::Project,
version: Some(LATEST_UPLOAD_METADATA_VERSION),
tokenless: false,
profile_md5: "tfC4VxYiYdJcTWpHpv4Ouw==".into(),
profile_encoding: Some("gzip".into()),
runner: Runner {
name: "codspeed-runner".into(),
version: "4.11.1".into(),
instruments: vec![],
executor: ExecutorName::Valgrind,
system_info: SystemInfo {
os: "nixos".to_string(),
os_version: "25.11".to_string(),
arch: "x86_64".to_string(),
host: "badlands".to_string(),
user: "guillaume".to_string(),
cpu_brand: "11th Gen Intel(R) Core(TM) i5-11400H @ 2.70GHz".to_string(),
cpu_name: "cpu0".to_string(),
cpu_vendor_id: "GenuineIntel".to_string(),
cpu_cores: 6,
total_memory_gb: 16,
cpu_flags: vec![
"sse2".to_string(),
"avx".to_string(),
"avx2".to_string(),
"erms".to_string(),
],
},
},
run_environment: RunEnvironment::Local,
commit_hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".into(),
allow_empty: false,
run_environment_metadata: RunEnvironmentMetadata {
ref_: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".into(),
head_ref: None,
base_ref: None,
owner: "GuillaumeLagrange".into(),
repository: "local-runs".into(),
event: RunEvent::Local,
gh_data: None,
sender: None,
gl_data: None,
local_data: Some(LocalData {
expected_run_parts_count: 1,
}),
repository_root_path: "/home/guillaume/codspeed/runner/".into(),
},
run_part: Some(RunPart {
run_id: "e0878123-c467-4191-994b-8560d8a7424e".into(),
run_part_id: "valgrind".into(),
job_name: "local-job".into(),
metadata: BTreeMap::new(),
}),
};
let hash = upload_metadata.get_hash();
assert_snapshot!(
hash,
// Caution: when changing this value, we need to ensure that
// the related backend snapshot remains the same
@"26c83ef306f189fe5b725043577dbc09a204bbd1c973dd7d1e974ff88235dd84"
);
assert_json_snapshot!(upload_metadata);
}
}