mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
test(operator): write more unit tests
This commit is contained in:
parent
30894885f0
commit
3732b7d8ba
@ -1,6 +1,7 @@
|
|||||||
package sqlschema
|
package sqlschema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -1094,7 +1095,8 @@ func TestOperatorAlterTable(t *testing.T) {
|
|||||||
Columns: []*Column{
|
Columns: []*Column{
|
||||||
{Name: "uuid", DataType: DataTypeText, Nullable: false, Default: ""},
|
{Name: "uuid", DataType: DataTypeText, Nullable: false, Default: ""},
|
||||||
},
|
},
|
||||||
PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"uuid"}},
|
PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"uuid"}},
|
||||||
|
ForeignKeyConstraints: []*ForeignKeyConstraint{},
|
||||||
},
|
},
|
||||||
expected: map[OperatorSupport][][]byte{
|
expected: map[OperatorSupport][][]byte{
|
||||||
{SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
|
{SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
|
||||||
@ -1114,11 +1116,19 @@ func TestOperatorAlterTable(t *testing.T) {
|
|||||||
[]byte(`DROP TABLE IF EXISTS "users"`),
|
[]byte(`DROP TABLE IF EXISTS "users"`),
|
||||||
[]byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
|
[]byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
|
||||||
// third drop to add the primary key constraint
|
// third drop to add the primary key constraint
|
||||||
[]byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" TEXT NOT NULL, "uuid" TEXT NOT NULL DEFAULT '', CONSTRAINT "pk_users" PRIMARY KEY ("uuid"))`),
|
[]byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("uuid" TEXT NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("uuid"))`),
|
||||||
[]byte(`INSERT INTO "users__temp" ("id", "uuid") SELECT "id", "uuid" FROM "users"`),
|
[]byte(`INSERT INTO "users__temp" ("uuid") SELECT "uuid" FROM "users"`),
|
||||||
[]byte(`DROP TABLE IF EXISTS "users"`),
|
[]byte(`DROP TABLE IF EXISTS "users"`),
|
||||||
[]byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
|
[]byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
|
||||||
},
|
},
|
||||||
|
{SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
|
||||||
|
[]byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "pk_users"`),
|
||||||
|
[]byte(`ALTER TABLE "users" DROP COLUMN IF EXISTS "id"`),
|
||||||
|
[]byte(`ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "uuid" TEXT`),
|
||||||
|
[]byte(`UPDATE "users" SET "uuid" = ''`),
|
||||||
|
[]byte(`ALTER TABLE "users" ALTER COLUMN "uuid" SET NOT NULL`),
|
||||||
|
[]byte(`ALTER TABLE "users" ADD CONSTRAINT "pk_users" PRIMARY KEY ("uuid")`),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1131,6 +1141,9 @@ func TestOperatorAlterTable(t *testing.T) {
|
|||||||
clonedTable := testCase.table.Clone()
|
clonedTable := testCase.table.Clone()
|
||||||
|
|
||||||
actuals := operator.AlterTable(clonedTable, testCase.uniqueConstraints, testCase.newTable)
|
actuals := operator.AlterTable(clonedTable, testCase.uniqueConstraints, testCase.newTable)
|
||||||
|
for _, sql := range actuals {
|
||||||
|
fmt.Println(string(sql))
|
||||||
|
}
|
||||||
assert.Equal(t, sqls, actuals)
|
assert.Equal(t, sqls, actuals)
|
||||||
assert.EqualValues(t, testCase.newTable, clonedTable)
|
assert.EqualValues(t, testCase.newTable, clonedTable)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user