#!/usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash setup() { setup_common } teardown() { assert_feature_version teardown_common } get_commit_hash() { local logline=$(dolt log -n "$1") echo ${logline:12:32} } @test "ci: init should create dolt ci workflow tables" { dolt ci init run dolt log -n 1 [ "$status" -eq 0 ] [[ "$output" =~ "Successfully initialized Dolt CI" ]] || false dolt sql -q "select * from dolt_ci_workflows;" dolt sql -q "select * from dolt_ci_workflow_events;" dolt sql -q "select * from dolt_ci_workflow_event_triggers;" dolt sql -q "select * from dolt_ci_workflow_event_trigger_branches;" dolt sql -q "select * from dolt_ci_workflow_jobs;" dolt sql -q "select * from dolt_ci_workflow_steps;" dolt sql -q "select * from dolt_ci_workflow_saved_query_steps;" dolt sql -q "select * from dolt_ci_workflow_saved_query_step_expected_row_column_results;" } @test "ci: destroy should destroy dolt ci workflow tables" { dolt ci init run dolt log -n 1 [ "$status" -eq 0 ] [[ "$output" =~ "Successfully initialized Dolt CI" ]] || false dolt sql -q "insert into dolt_ci_workflows values('workflow_1', now(), now());" dolt sql -q "insert into dolt_ci_workflow_events values(uuid(), 1, 'workflow_1');" dolt ci destroy run dolt log -n 1 [ "$status" -eq 0 ] [[ "$output" =~ "Successfully destroyed Dolt CI" ]] || false run dolt sql -q "select * from dolt_ci_workflows;" [ "$status" -eq 1 ] [[ "$output" =~ "table not found: dolt_ci_workflows" ]] || false } @test "ci: init should error if database has already initialized ci" { dolt ci init run dolt ci init [ "$status" -eq 1 ] [[ "$output" =~ "dolt ci has already been initialized" ]] || false } @test "ci: user cannot manually create ci tables in dolt_ci namespace" { run dolt sql -q "create table dolt_ci_workflows(pk int primary key);" [ "$status" -eq 1 ] [[ "$output" =~ "Invalid table name" ]] || false dolt sql -q "create table workflows(pk int primary key);" run dolt sql -q "rename table workflows to dolt_ci_workflows;" [ "$status" -eq 1 ] [[ "$output" =~ "Invalid table name" ]] || false } @test "ci: workflow tables do not appear in show tables output" { dolt ci init run dolt sql -q "show tables;" [ "$status" -eq 0 ] [[ ${output} != *"dolt_ci"* ]] || false } @test "ci: workflow tables do not appear in dolt ls" { dolt ci init run dolt ls [ "$status" -eq 0 ] [[ ${output} != *"dolt_ci"* ]] || false } @test "ci: workflow tables do appear in diffs" { first=$(get_commit_hash 1) dolt ci init last=$(get_commit_hash 1) run dolt diff "$first" "$last" --system [ "$status" -eq 0 ] [[ ${output} == *"dolt_ci"* ]] || false } @test "ci: init command should only commit changes relevant to the ci tables" { dolt sql -q "create table t1(pk int primary key);" dolt ci init dolt status run dolt status [ "$status" -eq 0 ] [[ "$output" =~ "Untracked tables:" ]] || false [[ "$output" =~ " (use \"dolt add