github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/testutils/sqlutils/sql_runner_test.go (about)

     1  // Copyright 2016 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package sqlutils_test
    12  
    13  import (
    14  	"context"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/base"
    18  	"github.com/cockroachdb/cockroach/pkg/testutils"
    19  	"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
    20  	"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
    21  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    22  )
    23  
    24  // Test that the RowsToStrMatrix doesn't swallow errors.
    25  func TestRowsToStrMatrixError(t *testing.T) {
    26  	defer leaktest.AfterTest(t)()
    27  
    28  	s, db, _ := serverutils.StartServer(t, base.TestServerArgs{})
    29  	defer s.Stopper().Stop(context.Background())
    30  
    31  	// We'll run a query that only fails after returning some rows, so that the
    32  	// error is discovered by RowsToStrMatrix below.
    33  	rows, err := db.Query(
    34  		"select case x when 5 then crdb_internal.force_error('00000', 'testing error') else x end from generate_series(1,5) as v(x);")
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	if _, err := sqlutils.RowsToStrMatrix(rows); !testutils.IsError(err, "testing error") {
    39  		t.Fatalf("expected 'testing error', got: %v", err)
    40  	}
    41  }