feat(go): add oem to identity binding schema

This commit is contained in:
lingniu
2026-07-03 15:31:52 +08:00
parent 9994f2baf4
commit 1d79dc25e0
2 changed files with 44 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package identity
import (
"context"
"database/sql"
"errors"
"strings"
"testing"
"time"
@@ -293,6 +294,27 @@ func TestMySQLResolverEnsuresMinimalIdentitySchema(t *testing.T) {
defer db.Close()
mock.ExpectExec("CREATE TABLE IF NOT EXISTS vehicle_identity_binding").
WillReturnResult(sqlmock.NewResult(0, 0))
mock.ExpectExec("ALTER TABLE vehicle_identity_binding ADD COLUMN oem").
WillReturnResult(sqlmock.NewResult(0, 0))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS jt808_registration").
WillReturnResult(sqlmock.NewResult(0, 0))
resolver := NewMySQLResolver(db, "vehicle_identity_binding")
if err := resolver.EnsureSchema(context.Background()); err != nil {
t.Fatalf("EnsureSchema() error = %v", err)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Fatalf("sql expectations: %v", err)
}
}
func TestMySQLResolverIgnoresExistingOEMColumn(t *testing.T) {
db, mock := newMockDB(t)
defer db.Close()
mock.ExpectExec("CREATE TABLE IF NOT EXISTS vehicle_identity_binding").
WillReturnResult(sqlmock.NewResult(0, 0))
mock.ExpectExec("ALTER TABLE vehicle_identity_binding ADD COLUMN oem").
WillReturnError(errors.New("Error 1060 (42S21): Duplicate column name 'oem'"))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS jt808_registration").
WillReturnResult(sqlmock.NewResult(0, 0))