File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
5
5
## [ Unreleased]
6
6
7
+ ### Fixed
8
+
9
+ - Truncate k8s event strings correctly, when required ([ #337 ] ).
10
+
11
+ [ #337 ] : https://github.com/stackabletech/operator-rs/pull/337
12
+
7
13
## [ 0.13.0] - 2022-02-23
8
14
9
15
### Added
Original file line number Diff line number Diff line change @@ -87,11 +87,13 @@ mod message {
87
87
const ELLIPSIS_LEN : usize = ELLIPSIS . len_utf8 ( ) ;
88
88
let len = msg. len ( ) ;
89
89
if len > max_len {
90
- msg. truncate ( find_start_of_char ( msg, len. saturating_sub ( ELLIPSIS_LEN ) ) ) ;
90
+ let start_of_trunc_char = find_start_of_char ( msg, max_len. saturating_sub ( ELLIPSIS_LEN ) ) ;
91
+ msg. truncate ( start_of_trunc_char) ;
91
92
if ELLIPSIS_LEN <= max_len {
92
93
msg. push ( ELLIPSIS ) ;
93
94
}
94
95
}
96
+ debug_assert ! ( msg. len( ) <= max_len) ;
95
97
}
96
98
97
99
fn find_start_of_char ( s : & str , mut pos : usize ) -> usize {
@@ -120,7 +122,10 @@ mod message {
120
122
fn truncate_should_ellipsize_large_string ( ) {
121
123
let mut x = "hello" . to_string ( ) ;
122
124
truncate_with_ellipsis ( & mut x, 4 ) ;
123
- assert_eq ! ( & x, "he…" ) ;
125
+ assert_eq ! ( & x, "h…" ) ;
126
+ x = "hello, this is a much larger string" . to_string ( ) ;
127
+ truncate_with_ellipsis ( & mut x, 4 ) ;
128
+ assert_eq ! ( & x, "h…" ) ;
124
129
}
125
130
126
131
#[ test]
You can’t perform that action at this time.
0 commit comments