From 1a05bf807f0587c252269db735fb41ecaec7e460 Mon Sep 17 00:00:00 2001 From: Christopher Moussa Date: Thu, 7 Nov 2024 13:15:56 -0800 Subject: [PATCH] t: edit tests to include custom formats, headers Problem: The tests for the pop-db and export-db commands are outdated with the improvements made to export_db_info() - namely, the inclusion of headers in the .csv file & the customization of output. Adjust the tests in t1009-pop-db.t and t1016-export-db.t to account for the changes made to export_db_info(). --- t/t1009-pop-db.t | 3 +++ t/t1016-export-db.t | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/t/t1009-pop-db.t b/t/t1009-pop-db.t index f80b5bd6..85b56886 100755 --- a/t/t1009-pop-db.t +++ b/t/t1009-pop-db.t @@ -22,6 +22,7 @@ test_expect_success 'start flux-accounting service' ' test_expect_success 'create a banks.csv file containing bank information' ' cat <<-EOF >banks.csv + bank,parent_bank,shares root,,1 A,root,1 B,root,1 @@ -36,6 +37,7 @@ test_expect_success 'populate flux-accounting DB with banks.csv' ' test_expect_success 'create a users.csv file containing user information' ' cat <<-EOF >users.csv + username,uid,bank,shares,max_running_jobs,max_active_jobs,max_nodes,queues user1000,1000,A,1,10,15,5,"" user1001,1001,A,1,10,15,5,"" user1002,1002,A,1,10,15,5,"" @@ -55,6 +57,7 @@ test_expect_success 'check database hierarchy to make sure all banks & users wer test_expect_success 'create a users.csv file with some missing optional user information' ' cat <<-EOF >users_optional_vals.csv + username,uid,bank,shares,max_running_jobs,max_active_jobs,max_nodes,queues user1005,1005,B,1,5,,5,"" user1006,1006,B,,,,5,"" user1007,1007,B,1,7,,,"" diff --git a/t/t1016-export-db.t b/t/t1016-export-db.t index 41d1d760..5a8335f1 100755 --- a/t/t1016-export-db.t +++ b/t/t1016-export-db.t @@ -38,12 +38,19 @@ test_expect_success 'add some users to the DB' ' flux account add-user --username=user5014 --userid=5014 --bank=C ' -test_expect_success 'export DB information into .csv files' ' - flux account export-db +# we only use custom formatting here because the creation_time and mod_time +# fields will be different from every run (since they are timestamps) +test_expect_success 'export bank DB information into .csv files' ' + flux account export-db \ + --banks=banks_test.csv \ + --users=users_test.csv \ + --bank-fields=bank,parent_bank,shares \ + --user-fields=username,userid,bank,shares,max_running_jobs,max_active_jobs,max_nodes,queues ' test_expect_success 'compare banks.csv' ' cat <<-EOF >banks_expected.csv + bank,parent_bank,shares root,,1 A,root,1 B,root,1 @@ -52,17 +59,33 @@ test_expect_success 'compare banks.csv' ' E,D,1 F,D,1 EOF - test_cmp -b banks_expected.csv banks.csv + test_cmp -b banks_expected.csv banks_test.csv ' test_expect_success 'compare users.csv' ' cat <<-EOF >users_expected.csv + username,userid,bank,shares,max_running_jobs,max_active_jobs,max_nodes,queues user5011,5011,A,1,5,7,2147483647, user5012,5012,A,1,5,7,2147483647, user5013,5013,B,1,5,7,2147483647, user5014,5014,C,1,5,7,2147483647, EOF - test_cmp -b users_expected.csv users.csv + test_cmp -b users_expected.csv users_test.csv +' + +test_expect_success 'export custom bank DB information' ' + flux account export-db --banks=banks_test_custom.csv --bank-fields=bank_id,bank && + cat <<-EOF >banks_expected_custom.csv + bank_id,bank + 1,root + 2,A + 3,B + 4,C + 5,D + 6,E + 7,F + EOF + test_cmp -b banks_expected_custom.csv banks_test_custom.csv ' test_expect_success 'create hierarchy output of the flux-accounting DB and store it in a file' ' @@ -82,8 +105,8 @@ test_expect_success 'restart service against new DB' ' ' test_expect_success 'import information into new DB' ' - flux account pop-db -b banks.csv && - flux account pop-db -u users.csv + flux account pop-db -b banks_test.csv && + flux account pop-db -u users_test.csv ' test_expect_success 'create hierarchy output of the new DB and store it in a file' ' @@ -95,7 +118,11 @@ test_expect_success 'compare DB hierarchies to make sure they are the same' ' ' test_expect_success 'specify a different filename for exported users and banks .csv files' ' - flux account export-db --users foo.csv --banks bar.csv && + flux account export-db \ + --banks=bar.csv \ + --users=foo.csv \ + --bank-fields=bank,parent_bank,shares \ + --user-fields=username,userid,bank,shares,max_running_jobs,max_active_jobs,max_nodes,queues && test_cmp -b users_expected.csv foo.csv && test_cmp -b banks_expected.csv bar.csv '