github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/tests/acceptance/test_files/migration.bats (about) 1 load "$LIB_BATS_ASSERT/load.bash" 2 load "$LIB_BATS_SUPPORT/load.bash" 3 4 ## public schema migration 5 6 @test "verify data is properly migrated when upgrading from v0.13.6" { 7 # setup sql statements 8 setup_sql[0]="create table sample(sample_col_1 char(10), sample_col_2 char(10))" 9 setup_sql[1]="insert into sample(sample_col_1,sample_col_2) values ('foo','bar')" 10 setup_sql[2]="insert into sample(sample_col_1,sample_col_2) values ('foo1','bar1')" 11 setup_sql[3]="create function sample_func() returns integer as 'select 1 as result;' language sql;" 12 13 # verify sql statements 14 verify_sql[0]="select * from sample" 15 verify_sql[1]="select * from sample_func()" 16 17 # create a temp directory to install steampipe(0.13.6) 18 tmpdir="$(mktemp -d)" 19 mkdir -p "${tmpdir}" 20 tmpdir="${tmpdir%/}" 21 22 # find the name of the zip file as per OS and arch 23 case $(uname -sm) in 24 "Darwin x86_64") target="darwin_amd64.zip" ;; 25 "Darwin arm64") target="darwin_arm64.zip" ;; 26 "Linux x86_64") target="linux_amd64.tar.gz" ;; 27 "Linux aarch64") target="linux_arm64.tar.gz" ;; 28 *) echo "Error: '$(uname -sm)' is not supported yet." 1>&2;exit 1 ;; 29 esac 30 31 # download the zip and extract 32 steampipe_uri="https://github.com/turbot/steampipe/releases/download/v0.13.6/steampipe_${target}" 33 case $(uname -s) in 34 "Darwin") zip_location="${tmpdir}/steampipe.zip" ;; 35 "Linux") zip_location="${tmpdir}/steampipe.tar.gz" ;; 36 *) echo "Error: steampipe is not supported on '$(uname -s)' yet." 1>&2;exit 1 ;; 37 esac 38 curl --fail --location --progress-bar --output "$zip_location" "$steampipe_uri" 39 tar -xf "$zip_location" -C "$tmpdir" 40 41 # start the service 42 $tmpdir/steampipe --install-dir $tmpdir service start 43 44 # execute the setup sql statements 45 for ((i = 0; i < ${#setup_sql[@]}; i++)); do 46 $tmpdir/steampipe --install-dir $tmpdir query "${setup_sql[$i]}" 47 done 48 49 # store the result of the verification statements(0.13.6) 50 for ((i = 0; i < ${#verify_sql[@]}; i++)); do 51 $tmpdir/steampipe --install-dir $tmpdir query "${verify_sql[$i]}" > verify$i.txt 52 done 53 54 # stop the service 55 $tmpdir/steampipe --install-dir $tmpdir service stop 56 57 # Now run this version - which should migrate the data 58 steampipe --install-dir $tmpdir service start 59 60 # store the result of the verification statements(0.14.*) 61 for ((i = 0; i < ${#verify_sql[@]}; i++)); do 62 echo "VerifySQL: ${verify_sql[$i]}" 63 steampipe --install-dir $tmpdir query "${verify_sql[$i]}" > verify$i$i.txt 64 done 65 66 # stop the service 67 steampipe --install-dir $tmpdir service stop 68 69 # verify data is migrated correctly 70 for ((i = 0; i < ${#verify_sql[@]}; i++)); do 71 assert_equal "$(cat verify$i.txt)" "$(cat verify$i$i.txt)" 72 done 73 74 rm -rf $tmpdir 75 rm -f verify* 76 } 77 78 function teardown_file() { 79 # list running processes 80 ps -ef | grep steampipe 81 82 # check if any processes are running 83 num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ') 84 assert_equal $num 0 85 } 86 87 function setup() { 88 # skip if this test is run on Linux ARM64, since there is no linux_arm binary available 89 # for v0.13.6 to run this test 90 sys=$(uname -sm) 91 if [[ "$sys" == "Linux aarch64" ]]; then 92 skip 93 else 94 echo "Running migration test..." 95 fi 96 }