#!/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 \" to include in what will be committed)" ]] || false [[ "$output" =~ " new table: t1" ]] || false } @test "ci: destroy command should only commit changes relevant to the ci tables" { dolt sql -q "create table t1(pk int primary key);" dolt ci init dolt ci destroy run dolt status [ "$status" -eq 0 ] [[ "$output" =~ "Untracked tables:" ]] || false [[ "$output" =~ " (use \"dolt add
\" to include in what will be committed)" ]] || false [[ "$output" =~ " new table: t1" ]] || false } @test "ci: import command will import a valid workflow.yaml file" { cat > workflow.yaml < workflow.yaml < workflow.yaml < workflow2.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow_1.yaml < workflow_1_updated.yaml < workflow.yaml <= 16" - name: assert act_symbol column exist saved_query_name: check volatility_history.act_symbol exists expected_columns: "== 1" - name: check data steps: - name: assert option_chain table has data saved_query_name: check option_chain data expected_rows: "> 0" - name: assert volatility_history table has data saved_query_name: check volatility_history data expected_rows: "> 0" EOF dolt ci init dolt ci import ./workflow.yaml run dolt ci import ./workflow.yaml [ "$status" -eq 0 ] [[ "$output" =~ "Dolt CI Workflow 'my first DoltHub workflow' up to date." ]] || false } @test "ci: ls lists existing workflows" { cat > workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow_1.yaml < workflow_2.yaml < workflow.yaml < workflow_1.yaml < workflow.yaml < workflow.yaml < workflow_1.yaml < workflow_1.yaml < workflow.yaml < workflow.yaml < workflow.yaml < 7" - name: greater or equal than comp saved_query_name: main expected_columns: ">= 8" - name: less than comp saved_query_name: main expected_columns: "< 9" - name: less or equal than comp saved_query_name: main expected_columns: "<= 8" EOF dolt ci init dolt ci import ./workflow.yaml dolt sql --save "main" -q "select * from dolt_commits;" run dolt ci run "workflow" [ "$status" -eq 0 ] [[ "$output" =~ "Running workflow: workflow" ]] || false [[ "$output" =~ "Step: equals comp" ]] || false [[ "$output" =~ "Step: not equals comp" ]] || false [[ "$output" =~ "Step: greater than comp" ]] || false [[ "$output" =~ "Step: greater or equal than comp" ]] || false [[ "$output" =~ "Step: less than comp" ]] || false [[ "$output" =~ "Step: less or equal than comp" ]] || false [[ "$output" =~ " - main - PASS" ]] || false } @test "ci: saved queries fail with ci run" { cat > workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow.yaml < workflow_test.yaml < workflow_group.yaml <