-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgit_txns.rs
More file actions
186 lines (172 loc) · 6.79 KB
/
git_txns.rs
File metadata and controls
186 lines (172 loc) · 6.79 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Tackler-NG 2019-2025
* SPDX-License-Identifier: Apache-2.0
*/
mod git_txns {
use indoc::formatdoc;
use std::path::Path;
use tackler_api::metadata::items::MetadataItem;
use tackler_core::kernel::Settings;
use tackler_core::kernel::settings::GitInputSelector;
use tackler_core::model::TxnData;
use tackler_core::{parser, tackler};
use tackler_rs::IndocUtils;
// val cfg = ConfigFactory.parseString(
// """
// |{
// | # ./ = non-forked JVM
// | # ../ = forked JVM
// | basedir = "../tests/audit/"
// | input {
// | storage = git
// | git {
// | repository = "audit-repo.git"
// | dir = "txns/2016"
// | suffix = ".txn"
// | }
// | }
// |}
// """.stripMargin)
const REPO_PATH: &str = "../suite/audit/audit-repo.git/";
const TXN_SET_1E1_CHECKSUM: &str =
"4a0eb2f8836447a025030a87136c047b4a737031162f593cb00f390c6ba113a3";
const TXN_SET_1E1_COMMIT_ID: &str = "ed6e4b10de2daea8d143569c473d14a9b09c3270";
const UUID_01: &str = "72f7b85b-42ce-4fa2-971e-5ba5fc196d9d";
const TXN_SET_1E1_TXN01_CHECKSUM: &str =
"69724dbe40e9077ba79387931f5c6188d41dca84a2098b2a1e48ebe5472ae287";
const TXN_SET_1E5_CHECKSUM: &str =
"2f4bc22df78502182aa27037d8d0f72462adb018be3e768399e0b803fa75baa7";
const TXN_SET_1E5_COMMIT_ID: &str = "4648a2994b41ed341b544a148b3060fd2d267d79";
fn verify_git_run(result: &Result<TxnData, tackler::Error>, commit: &str, checksum: &str) {
match result {
Ok(txn_data) => {
let txn_set = txn_data.get_all().unwrap(/*:test:*/);
match txn_set.metadata() {
Some(md) => {
assert_eq!(md.items.len(), 2, "Metadata Item count is wrong");
match &md.items[0] {
MetadataItem::GitInputReference(gitmd) => {
assert_eq!(gitmd.commit, commit);
}
_ => {
panic!(/*:test:*/ "item is not Git Input Metadata item")
}
}
match &md.items[1] {
MetadataItem::TxnSetChecksum(tscsmd) => {
assert_eq!(tscsmd.hash.value, checksum);
}
_ => {
panic!(/*:test:*/ "item is not Txn Set Checksum Metadata item")
}
}
}
None => {
panic!(/*:test:*/ "no metadata")
}
}
}
Err(err) => {
panic!(/*:test:*/ "{err:#?}");
}
}
}
#[test]
// test: ce2e6523-ee83-46e7-a767-441c5b9f2802
// desc: "handle ref with 10 (1E1) txns"
fn normal_txns_1e1() {
let result = parser::git_to_txns(
Path::new(REPO_PATH),
"txns/2016",
"txn",
GitInputSelector::Reference("set-1e1".to_string()),
&mut Settings::default_audit(),
);
verify_git_run(&result, TXN_SET_1E1_COMMIT_ID, TXN_SET_1E1_CHECKSUM);
}
#[test]
// test: 5b193a18-9341-4c33-bc88-003411c4c2fc
// desc: "TxnData Append will reset metadata"
fn txndata_append_resets_metadata() {
#[rustfmt::skip]
let str_txn_01 = formatdoc!(
"2019-01-01 'txn01
| # uuid: {UUID_01}
| e 1
| a
|"
).strip_margin();
let result = parser::git_to_txns(
Path::new(REPO_PATH),
"txns/2016",
"txn",
GitInputSelector::Reference("set-1e1".to_string()),
&mut Settings::default_audit(),
);
verify_git_run(&result, TXN_SET_1E1_COMMIT_ID, TXN_SET_1E1_CHECKSUM);
let mut txns = result.unwrap();
let mut txns_01 = parser::string_to_txns(
&mut str_txn_01.as_str(), &mut Settings::default_audit()).unwrap(/*:test:*/);
let txn_set = txns.append(&mut txns_01).unwrap(/*:test:*/).get_all().unwrap(/*:test:*/);
match txn_set.metadata() {
Some(md) => {
assert_eq!(md.items.len(), 1, "Metadata Item count is wrong");
match &md.items[0] {
MetadataItem::TxnSetChecksum(tscsmd) => {
assert_eq!(tscsmd.hash.value, TXN_SET_1E1_TXN01_CHECKSUM);
}
_ => {
panic!(/*:test:*/ "item is not Txn Set Checksum Metadata item")
}
}
}
None => {
panic!(/*:test:*/ "no metadata")
}
}
}
#[test]
// test: 074f5549-346c-4780-90a1-07d60ae0e79d
// desc: "handle ref with 100_000 (1E5) txns"
fn normal_txns_1e5() {
let result = parser::git_to_txns(
Path::new(REPO_PATH),
"txns/2016",
"txn",
GitInputSelector::Reference("set-1e5".to_string()),
&mut Settings::default_audit(),
);
verify_git_run(&result, TXN_SET_1E5_COMMIT_ID, TXN_SET_1E5_CHECKSUM);
}
#[test]
// test: a6cfe3b6-feec-4422-afbf-faeca5baf752
// desc: "report reasonable details in case of audit error"
fn test_git_error_reporting() {
// See txn_header.rs::parse_txn_header
//
// GIT: Error while processing git object
// commit id: c984f946d1b76e3a175a07542859baf09be18c89
// object id: 82d58a5c5b2928baee5e93f1143e88a442087ebe
// path: txns/2016/04/01/20160401T120000-26.txn
// msg : Audit mode is activated and there is a txn without UUID ...
//
let result = parser::git_to_txns(
Path::new(REPO_PATH),
"txns/2016",
"txn",
GitInputSelector::Reference("err-1e2".to_string()),
&mut Settings::default_audit(),
);
assert!(result.is_err());
let msg = result.err().unwrap(/*:test:*/).to_string();
assert!(msg.contains("c984f946d1b76e3a175a07542859baf09be18c89"));
// git ls-tree \
// c984f946d1b76e3a175a07542859baf09be18c89 \
// txns/2016/04/01/20160401T120000-26.txn
assert!(msg.contains("82d58a5c5b2928baee5e93f1143e88a442087ebe"));
assert!(msg.contains("without UUID"));
assert!(msg.contains("path: txns/2016/04/01/20160401T120000-26.txn"));
assert!(msg.contains("txn date: 2016-04-01T12:00:00+00:00[UTC]"));
assert!(msg.contains("txn code: #0000026"));
}
}