Skip to content

Commit

Permalink
fix(generators): introduce function that runs the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kropachev committed Jun 6, 2023
1 parent 40cabe6 commit 3ff0fb5
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 204 deletions.
114 changes: 33 additions & 81 deletions pkg/generators/schema_check_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,110 +12,62 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:thelper
package generators

import (
"path"
"testing"

"github.com/scylladb/gemini/pkg/utils"
)

var checkDataPath = "./test_expected_data/check/"

// GenCheck functions tests
func TestGenSinglePartitionQuery(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, checkDataPath, "single_partition.json", genSinglePartitionQueryCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genSinglePartitionQueryCases {
caseName := genSinglePartitionQueryCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genSinglePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(checkDataPath, "single_partition.json"), genSinglePartitionQueryCases, func(subT *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genSinglePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}

func TestGenMultiplePartitionQuery(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, checkDataPath, "multiple_partition.json", genMultiplePartitionQueryCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genMultiplePartitionQueryCases {
caseName := genMultiplePartitionQueryCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genMultiplePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(checkDataPath, "multiple_partition.json"), genMultiplePartitionQueryCases, func(subT *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genMultiplePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}

func TestGenClusteringRangeQuery(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, checkDataPath, "clustering_range.json", genClusteringRangeQueryCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genClusteringRangeQueryCases {
caseName := genClusteringRangeQueryCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.ckCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(checkDataPath, "clustering_range.json"), genClusteringRangeQueryCases, func(subT *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.ckCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}

func TestGenMultiplePartitionClusteringRangeQuery(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, checkDataPath, "multiple_partition_clustering_range.json", genMultiplePartitionClusteringRangeQueryCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genMultiplePartitionClusteringRangeQueryCases {
caseName := genMultiplePartitionClusteringRangeQueryCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genMultiplePartitionClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount, opts.ckCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(checkDataPath, "multiple_partition_clustering_range.json"), genMultiplePartitionClusteringRangeQueryCases,
func(subT *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genMultiplePartitionClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount, opts.ckCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}

func TestGenSingleIndexQuery(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, checkDataPath, "single_index.json", genSingleIndexQueryCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genSingleIndexQueryCases {
caseName := genSingleIndexQueryCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genSingleIndexQuery(schema, schema.Tables[0], gen, rnd, prc, opts.idxCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(checkDataPath, "single_index.json"), genSingleIndexQueryCases, func(subT *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt := genSingleIndexQuery(schema, schema.Tables[0], gen, rnd, prc, opts.idxCount)
validateStmt(subT, stmt, nil)
expected.CompareOrStore(subT, caseName, stmt)
})
}

func BenchmarkGenSinglePartitionQuery(t *testing.B) {
Expand Down
49 changes: 15 additions & 34 deletions pkg/generators/schema_ddl_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:thelper
package generators

import (
"path"
"strconv"
"strings"
"testing"
Expand All @@ -26,43 +28,21 @@ import (
var ddlDataPath = "./test_expected_data/ddl/"

func TestGenDropColumnStmt(t *testing.T) {
utils.SetUnderTest()
t.Parallel()

expected := initExpected(t, ddlDataPath, "drop_column.json", genDropColumnStmtCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genDropColumnStmtCases {
caseName := genDropColumnStmtCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, _, _, _, opts := getAllForTestStmt(subT, caseName)
stmt, err := genDropColumnStmt(schema.Tables[0], schema.Keyspace.Name, opts.delNum)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(ddlDataPath, "drop_column.json"), genDropColumnStmtCases, func(subT *testing.T, caseName string, expected *expectedStore) {
schema, _, _, _, opts := getAllForTestStmt(subT, caseName)
stmt, err := genDropColumnStmt(schema.Tables[0], schema.Keyspace.Name, opts.delNum)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}

func TestGenAddColumnStmt(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
checkOnAllTypesInAddColumnCases(t, genAddColumnStmtCases)
expected := initExpected(t, ddlDataPath, "add_column.json", genAddColumnStmtCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genAddColumnStmtCases {
caseName := genAddColumnStmtCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, _, _, _, opts := getAllForTestStmt(subT, caseName)
stmt, err := genAddColumnStmt(schema.Tables[0], schema.Keyspace.Name, &opts.addType)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(ddlDataPath, "add_column.json"), genAddColumnStmtCases, func(subT *testing.T, caseName string, expected *expectedStore) {
schema, _, _, _, opts := getAllForTestStmt(subT, caseName)
stmt, err := genAddColumnStmt(schema.Tables[0], schema.Keyspace.Name, &opts.addType)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}

func BenchmarkGenDropColumnStmt(t *testing.B) {
Expand Down Expand Up @@ -95,6 +75,7 @@ func BenchmarkGenAddColumnStmt(t *testing.B) {
}
}

//nolint:unused
func checkOnAllTypesInAddColumnCases(t *testing.T, cases []string) {
founded := 0
for j := 0; j < len(coltypes.AllTypes); j++ {
Expand Down
122 changes: 42 additions & 80 deletions pkg/generators/schema_mutation_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:thelper
package generators

import (
"path"
"testing"

"github.com/scylladb/gemini/pkg/utils"
Expand All @@ -23,90 +25,50 @@ import (
var mutateDataPath = "./test_expected_data/mutate/"

func TestGenInsertStmt(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, mutateDataPath, "insert.json", genInsertStmtCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genInsertStmtCases {
caseName := genInsertStmtCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
stmt, err := genInsertStmt(schema, schema.Tables[0], gen.Get(), rnd, prc, opts.useLWT)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(mutateDataPath, "insert.json"), genInsertStmtCases, func(t *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, opts := getAllForTestStmt(t, caseName)
stmt, err := genInsertStmt(schema, schema.Tables[0], gen.Get(), rnd, prc, opts.useLWT)
validateStmt(t, stmt, err)
expected.CompareOrStore(t, caseName, stmt)
})
}

func TestGenInsertJSONStmt(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, mutateDataPath, "insert_j.json", genInsertJSONStmtCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genInsertJSONStmtCases {
caseName := genInsertJSONStmtCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, _ := getAllForTestStmt(subT, caseName)
stmt, err := genInsertJSONStmt(schema, schema.Tables[0], gen.Get(), rnd, prc)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(mutateDataPath, "insert_j.json"), genInsertJSONStmtCases, func(t *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, _ := getAllForTestStmt(t, caseName)
stmt, err := genInsertJSONStmt(schema, schema.Tables[0], gen.Get(), rnd, prc)
validateStmt(t, stmt, err)
expected.CompareOrStore(t, caseName, stmt)
})
}

func TestGenUpdateStmt(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, mutateDataPath, "update.json", genUpdateStmtCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genUpdateStmtCases {
caseName := genUpdateStmtCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, _ := getAllForTestStmt(subT, caseName)
stmt, err := genUpdateStmt(schema, schema.Tables[0], gen.Get(), rnd, prc)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(mutateDataPath, "update.json"), genUpdateStmtCases, func(t *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, _ := getAllForTestStmt(t, caseName)
stmt, err := genUpdateStmt(schema, schema.Tables[0], gen.Get(), rnd, prc)
validateStmt(t, stmt, err)
expected.CompareOrStore(t, caseName, stmt)
})
}

func TestGenDeleteRows(t *testing.T) {
utils.SetUnderTest()
t.Parallel()
expected := initExpected(t, mutateDataPath, "delete.json", genDeleteStmtCases, *updateExpected)
if *updateExpected {
defer expected.updateExpected(t)
}
for idx := range genDeleteStmtCases {
caseName := genDeleteStmtCases[idx]
t.Run(caseName,
func(subT *testing.T) {
schema, prc, gen, rnd, _ := getAllForTestStmt(subT, caseName)
stmt, err := genDeleteRows(schema, schema.Tables[0], gen.Get(), rnd, prc)
validateStmt(subT, stmt, err)
expected.CompareOrStore(subT, caseName, stmt)
})
}
RunStmtTest(t, path.Join(mutateDataPath, "delete.json"), genDeleteStmtCases, func(t *testing.T, caseName string, expected *expectedStore) {
schema, prc, gen, rnd, _ := getAllForTestStmt(t, caseName)
stmt, err := genDeleteRows(schema, schema.Tables[0], gen.Get(), rnd, prc)
validateStmt(t, stmt, err)
expected.CompareOrStore(t, caseName, stmt)
})
}

func BenchmarkGenInsertStmt(t *testing.B) {
utils.SetUnderTest()
for idx := range genInsertStmtCases {
caseName := genInsertStmtCases[idx]
t.Run(caseName,
func(subT *testing.B) {
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName)
subT.ResetTimer()
for x := 0; x < subT.N; x++ {
func(t *testing.B) {
schema, prc, gen, rnd, opts := getAllForTestStmt(t, caseName)
t.ResetTimer()
for x := 0; x < t.N; x++ {
_, _ = genInsertStmt(schema, schema.Tables[0], gen.Get(), rnd, prc, opts.useLWT)
}
})
Expand All @@ -118,10 +80,10 @@ func BenchmarkGenInsertJSONStmt(t *testing.B) {
for idx := range genInsertJSONStmtCases {
caseName := genInsertJSONStmtCases[idx]
t.Run(caseName,
func(subT *testing.B) {
schema, prc, gen, rnd, _ := getAllForTestStmt(subT, caseName)
subT.ResetTimer()
for x := 0; x < subT.N; x++ {
func(t *testing.B) {
schema, prc, gen, rnd, _ := getAllForTestStmt(t, caseName)
t.ResetTimer()
for x := 0; x < t.N; x++ {
_, _ = genInsertJSONStmt(schema, schema.Tables[0], gen.Get(), rnd, prc)
}
})
Expand All @@ -133,10 +95,10 @@ func BenchmarkGenUpdateStmt(t *testing.B) {
for idx := range genUpdateStmtCases {
caseName := genUpdateStmtCases[idx]
t.Run(caseName,
func(subT *testing.B) {
schema, prc, gen, rnd, _ := getAllForTestStmt(subT, caseName)
subT.ResetTimer()
for x := 0; x < subT.N; x++ {
func(t *testing.B) {
schema, prc, gen, rnd, _ := getAllForTestStmt(t, caseName)
t.ResetTimer()
for x := 0; x < t.N; x++ {
_, _ = genUpdateStmt(schema, schema.Tables[0], gen.Get(), rnd, prc)
}
})
Expand All @@ -148,10 +110,10 @@ func BenchmarkGenDeleteRows(t *testing.B) {
for idx := range genDeleteStmtCases {
caseName := genDeleteStmtCases[idx]
t.Run(caseName,
func(subT *testing.B) {
schema, prc, gen, rnd, _ := getAllForTestStmt(subT, caseName)
subT.ResetTimer()
for x := 0; x < subT.N; x++ {
func(t *testing.B) {
schema, prc, gen, rnd, _ := getAllForTestStmt(t, caseName)
t.ResetTimer()
for x := 0; x < t.N; x++ {
_, _ = genDeleteRows(schema, schema.Tables[0], gen.Get(), rnd, prc)
}
})
Expand Down
Loading

0 comments on commit 3ff0fb5

Please sign in to comment.