|
| 1 | +// Copyright 2023 Datafuse Labs. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use chrono::TimeZone; |
| 16 | +use chrono::Utc; |
| 17 | +use fastrace::func_name; |
| 18 | + |
| 19 | +use crate::common; |
| 20 | + |
| 21 | +// These bytes are built when a new version in introduced, |
| 22 | +// and are kept for backward compatibility test. |
| 23 | +// |
| 24 | +// ************************************************************* |
| 25 | +// * These messages should never be updated, * |
| 26 | +// * only be added when a new version is added, * |
| 27 | +// * or be removed when an old version is no longer supported. * |
| 28 | +// ************************************************************* |
| 29 | +// |
| 30 | +// The message bytes are built from the output of `test_pb_from_to()` |
| 31 | +#[test] |
| 32 | +fn test_decode_v156_data_mask() -> anyhow::Result<()> { |
| 33 | + let datamask_meta_v156 = vec![ |
| 34 | + 18, 6, 83, 116, 114, 105, 110, 103, 26, 68, 67, 65, 83, 69, 32, 87, 72, 69, 78, 32, 99, |
| 35 | + 117, 114, 114, 101, 110, 116, 95, 114, 111, 108, 101, 40, 41, 32, 73, 78, 40, 39, 65, 78, |
| 36 | + 65, 76, 89, 83, 84, 39, 41, 32, 84, 72, 69, 78, 32, 86, 65, 76, 32, 69, 76, 83, 69, 32, 39, |
| 37 | + 42, 42, 42, 42, 42, 42, 42, 42, 42, 39, 32, 69, 78, 68, 34, 12, 115, 111, 109, 101, 32, 99, |
| 38 | + 111, 109, 109, 101, 110, 116, 42, 23, 50, 48, 49, 52, 45, 49, 49, 45, 50, 56, 32, 49, 50, |
| 39 | + 58, 48, 48, 58, 48, 57, 32, 85, 84, 67, 50, 23, 50, 48, 49, 52, 45, 49, 49, 45, 50, 56, 32, |
| 40 | + 49, 50, 58, 48, 48, 58, 48, 57, 32, 85, 84, 67, 58, 14, 10, 4, 116, 101, 115, 116, 18, 6, |
| 41 | + 83, 116, 114, 105, 110, 103, 58, 11, 10, 1, 97, 18, 6, 83, 116, 114, 105, 110, 103, 160, 6, |
| 42 | + 156, 1, 168, 6, 24, |
| 43 | + ]; |
| 44 | + |
| 45 | + let want = || databend_common_meta_app::data_mask::DatamaskMeta { |
| 46 | + args: vec![ |
| 47 | + ("test".to_string(), "String".to_string()), |
| 48 | + ("a".to_string(), "String".to_string()), |
| 49 | + ], |
| 50 | + return_type: "String".to_string(), |
| 51 | + body: "CASE WHEN current_role() IN('ANALYST') THEN VAL ELSE '*********' END".to_string(), |
| 52 | + comment: Some("some comment".to_string()), |
| 53 | + create_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(), |
| 54 | + update_on: Some(Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap()), |
| 55 | + }; |
| 56 | + |
| 57 | + common::test_pb_from_to(func_name!(), want())?; |
| 58 | + common::test_load_old(func_name!(), datamask_meta_v156.as_slice(), 156, want()) |
| 59 | +} |
0 commit comments