Skip to content

Commit

Permalink
add GrantObject::Table/DatabaseById meta proto test
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Dec 20, 2023
1 parent 4523a34 commit 13925c5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/meta/proto-conv/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const META_CHANGE_LOG: &[(u64, &str)] = &[
(64, "2023-11-16: Add: user.proto/NDJsonFileFormatParams add field `missing_field_as` and `null_field_as`", ),
(65, "2023-11-16: Retype: use Datetime<Utc> instead of u64 to in lvt.time", ),
(66, "2023-12-15: Add: stage.proto/StageInfo::created_on", ),
(67, "2023-12-20: Add: user.proto/GrantTableIdObject and GrantDatabaseIdObject", ),
// Dear developer:
// If you're gonna add a new metadata version, you'll have to add a test for it.
// You could just copy an existing test file(e.g., `../tests/it/v024_table_meta.rs`)
Expand Down
1 change: 1 addition & 0 deletions src/meta/proto-conv/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ mod v063_connection;
mod v064_ndjson_format_params;
mod v065_least_visible_time;
mod v066_stage_create_on;
mod v067_user_grant_id;
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v063_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::common;
fn test_decode_v62_connection() -> anyhow::Result<()> {
let user_defined_connection_v62 = vec![
10, 7, 109, 121, 95, 99, 111, 110, 110, 18, 2, 115, 51, 26, 10, 10, 3, 107, 101, 121, 18,
3, 118, 97, 108, 160, 6, 62, 168, 6, 24,
3, 118, 97, 108, 160, 6, 63, 168, 6, 24,
];
let want = || UserDefinedConnection {
name: "my_conn".to_string(),
Expand All @@ -43,7 +43,7 @@ fn test_decode_v62_connection() -> anyhow::Result<()> {
common::test_load_old(
func_name!(),
user_defined_connection_v62.as_slice(),
62,
63,
want(),
)?;
Ok(())
Expand Down
68 changes: 68 additions & 0 deletions src/meta/proto-conv/tests/it/v067_user_grant_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2023 Datafuse Labs.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashSet;

use databend_common_meta_app as mt;
use databend_common_meta_app::principal::UserGrantSet;
use databend_common_meta_app::principal::UserPrivilegeType;
use enumflags2::make_bitflags;
use minitrace::func_name;

use crate::common;

// These bytes are built when a new version in introduced,
// and are kept for backward compatibility test.
//
// *************************************************************
// * These messages should never be updated, *
// * only be added when a new version is added, *
// * or be removed when an old version is no longer supported. *
// *************************************************************
//
// The user_info_v67 bytes are built from the output of `test_pb_from_to()`
#[test]
fn test_decode_v67_user() -> anyhow::Result<()> {
let user_info_v67 = vec![
10, 2, 117, 49, 18, 1, 37, 26, 8, 10, 0, 160, 6, 67, 168, 6, 24, 34, 70, 10, 31, 10, 21,
58, 13, 10, 7, 100, 101, 102, 97, 117, 108, 116, 16, 1, 24, 10, 160, 6, 67, 168, 6, 24, 16,
4, 160, 6, 67, 168, 6, 24, 10, 29, 10, 19, 50, 11, 10, 7, 100, 101, 102, 97, 117, 108, 116,
16, 1, 160, 6, 67, 168, 6, 24, 16, 2, 160, 6, 67, 168, 6, 24, 160, 6, 67, 168, 6, 24, 42,
6, 160, 6, 67, 168, 6, 24, 50, 6, 160, 6, 67, 168, 6, 24, 160, 6, 67, 168, 6, 24,
];
let want = || mt::principal::UserInfo {
name: "u1".to_string(),
hostname: "%".to_string(),
auth_info: Default::default(),
grants: UserGrantSet::new(
vec![
mt::principal::GrantEntry::new(
mt::principal::GrantObject::TableById("default".to_string(), 1, 10),
make_bitflags!(UserPrivilegeType::{Select}),
),
mt::principal::GrantEntry::new(
mt::principal::GrantObject::DatabaseById("default".to_string(), 1),
make_bitflags!(UserPrivilegeType::{Create}),
),
],
HashSet::new(),
),
quota: Default::default(),
option: Default::default(),
};
common::test_pb_from_to(func_name!(), want())?;
common::test_load_old(func_name!(), user_info_v67.as_slice(), 67, want())?;

Ok(())
}

0 comments on commit 13925c5

Please sign in to comment.