mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
127 lines
3.2 KiB
Go
127 lines
3.2 KiB
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/log/tag"
|
|
"go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/tests/testutils"
|
|
"go.temporal.io/server/tools/common/schema"
|
|
)
|
|
|
|
type (
|
|
// DB is a test interface for a database that supports schema tool
|
|
DB interface {
|
|
schema.DB
|
|
CreateDatabase(name string) error
|
|
DropDatabase(name string) error
|
|
ListTables() ([]string, error)
|
|
}
|
|
// DBTestBase is the base for all test suites that test
|
|
// the functionality of a DB implementation
|
|
DBTestBase struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
Log log.Logger
|
|
DBName string
|
|
db DB
|
|
}
|
|
)
|
|
|
|
// SetupSuiteBase sets up the test suite
|
|
func (tb *DBTestBase) SetupSuiteBase(db DB) {
|
|
tb.Assertions = require.New(tb.T()) // Have to define our overridden assertions in the test setup. If we did it earlier, tb.T() will return nil
|
|
tb.Log = log.NewTestLogger()
|
|
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
tb.DBName = fmt.Sprintf("db_client_test_%v", rand.Int63())
|
|
err := db.CreateDatabase(tb.DBName)
|
|
if err != nil {
|
|
tb.Log.Fatal("error creating database, ", tag.Error(err))
|
|
}
|
|
tb.db = db
|
|
}
|
|
|
|
// TearDownSuiteBase tears down the test suite
|
|
func (tb *DBTestBase) TearDownSuiteBase() {
|
|
tb.NoError(tb.db.DropDatabase(tb.DBName))
|
|
tb.db.Close()
|
|
}
|
|
|
|
// RunParseFileTest runs a test against the ParseFile method
|
|
func (tb *DBTestBase) RunParseFileTest(content string) {
|
|
rootDir := testutils.MkdirTemp(tb.T(), "", "dbClientTestDir")
|
|
cqlFile := testutils.CreateTemp(tb.T(), rootDir, "parseCQLTest")
|
|
|
|
_, err := cqlFile.WriteString(content)
|
|
tb.NoError(err)
|
|
stmts, err := persistence.LoadAndSplitQuery([]string{cqlFile.Name()})
|
|
tb.Nil(err)
|
|
tb.Equal(2, len(stmts), "wrong number of sql statements")
|
|
}
|
|
|
|
// RunCreateTest tests schema version table creation
|
|
func (tb *DBTestBase) RunCreateTest(db DB) {
|
|
tables, err := db.ListTables()
|
|
tb.Nil(err)
|
|
tb.Equal(0, len(tables))
|
|
|
|
err = db.CreateSchemaVersionTables()
|
|
tb.Nil(err)
|
|
|
|
expectedTables := make(map[string]struct{})
|
|
expectedTables["schema_version"] = struct{}{}
|
|
expectedTables["schema_update_history"] = struct{}{}
|
|
|
|
tables, err = db.ListTables()
|
|
tb.Nil(err)
|
|
tb.Equal(len(expectedTables), len(tables))
|
|
|
|
for _, t := range tables {
|
|
_, ok := expectedTables[t]
|
|
tb.True(ok)
|
|
delete(expectedTables, t)
|
|
}
|
|
tb.Equal(0, len(expectedTables))
|
|
}
|
|
|
|
// RunUpdateTest tests update of schema and schema version tables
|
|
func (tb *DBTestBase) RunUpdateTest(db DB) {
|
|
err := db.UpdateSchemaVersion("10.0", "5.0")
|
|
tb.Nil(err)
|
|
err = db.WriteSchemaUpdateLog("9.0", "10.0", "abc", "test")
|
|
tb.Nil(err)
|
|
|
|
ver, err := db.ReadSchemaVersion()
|
|
tb.Nil(err)
|
|
tb.Equal("10.0", ver)
|
|
|
|
err = db.UpdateSchemaVersion("12.0", "5.0")
|
|
tb.Nil(err)
|
|
ver, err = db.ReadSchemaVersion()
|
|
tb.Nil(err)
|
|
tb.Equal("12.0", ver)
|
|
}
|
|
|
|
// RunDropTest tests the drop methods in DB implementation
|
|
func (tb *DBTestBase) RunDropTest(db DB) {
|
|
tables, err := db.ListTables()
|
|
tb.Nil(err)
|
|
tb.True(len(tables) > 0)
|
|
|
|
err = db.DropAllTables()
|
|
tb.Nil(err)
|
|
|
|
tables, err = db.ListTables()
|
|
tb.Nil(err)
|
|
tb.Equal(0, len(tables))
|
|
|
|
_, err = db.ReadSchemaVersion()
|
|
tb.NotNil(err)
|
|
|
|
}
|