github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/workload/workload_test.go (about)

     1  // Copyright 2017 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 workload_test
    12  
    13  import (
    14  	"testing"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/testutils"
    17  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    18  	"github.com/cockroachdb/cockroach/pkg/workload"
    19  )
    20  
    21  func TestGet(t *testing.T) {
    22  	defer leaktest.AfterTest(t)()
    23  	if _, err := workload.Get(`bank`); err != nil {
    24  		t.Errorf(`expected success got: %+v`, err)
    25  	}
    26  	if _, err := workload.Get(`nope`); !testutils.IsError(err, `unknown generator`) {
    27  		t.Errorf(`expected "unknown generator" error got: %+v`, err)
    28  	}
    29  }
    30  
    31  func TestApproxDatumSize(t *testing.T) {
    32  	defer leaktest.AfterTest(t)()
    33  
    34  	tests := []struct {
    35  		datum interface{}
    36  		size  int64
    37  	}{
    38  		{nil, 0},
    39  		{int(-1000000), 3},
    40  		{int(-1000), 2},
    41  		{int(-1), 1},
    42  		{int(0), 1},
    43  		{int(1), 1},
    44  		{int(1000), 2},
    45  		{int(1000000), 3},
    46  		{float64(0), 1},
    47  		{float64(3), 8},
    48  		{float64(3.1), 8},
    49  		{float64(3.14), 8},
    50  		{float64(3.141), 8},
    51  		{float64(3.1415), 8},
    52  		{float64(3.14159), 8},
    53  		{float64(3.141592), 8},
    54  		{"", 0},
    55  		{"a", 1},
    56  		{"aa", 2},
    57  	}
    58  	for _, test := range tests {
    59  		if size := workload.ApproxDatumSize(test.datum); size != test.size {
    60  			t.Errorf(`%T: %v got %d expected %d`, test.datum, test.datum, size, test.size)
    61  		}
    62  	}
    63  }