You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/09/25 08:31:09 UTC

[incubator-devlake] branch main updated: refactor: LockTable be able to detect table type (#6142)

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 552ea0b51 refactor: LockTable be able to detect table type (#6142)
552ea0b51 is described below

commit 552ea0b5155df1498ca1ab055f6afc101b028526
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Mon Sep 25 16:31:04 2023 +0800

    refactor: LockTable be able to detect table type (#6142)
    
    * refactor: LockTable be able to detect table type
    
    * fix: avoid using DeepEqual against errors
---
 backend/core/dal/dal.go                        | 16 ++++++++--------
 backend/core/models/common/iso8601time_test.go |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/backend/core/dal/dal.go b/backend/core/dal/dal.go
index 4a5b97b62..5737922bd 100644
--- a/backend/core/dal/dal.go
+++ b/backend/core/dal/dal.go
@@ -184,19 +184,19 @@ type Dal interface {
 }
 
 type LockTable struct {
-	Table     string
-	Tabler    Tabler
+	Table     interface{}
 	Exclusive bool
 }
 
 func (l *LockTable) TableName() string {
-	if l.Table != "" {
-		return l.Table
+	switch table := l.Table.(type) {
+	case Tabler:
+		return table.TableName()
+	case string:
+		return table
+	default:
+		panic("either Table or Tabler must be specified")
 	}
-	if l.Tabler != nil {
-		return l.Tabler.TableName()
-	}
-	panic("either Table or Tabler must be specified")
 }
 
 type LockTables []*LockTable
diff --git a/backend/core/models/common/iso8601time_test.go b/backend/core/models/common/iso8601time_test.go
index 887ce59b5..380c4b9f1 100644
--- a/backend/core/models/common/iso8601time_test.go
+++ b/backend/core/models/common/iso8601time_test.go
@@ -23,6 +23,8 @@ import (
 	"reflect"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
 )
 
 type Iso8601TimeRecord struct {
@@ -118,9 +120,7 @@ func TestIso8601Time_Scan(t *testing.T) {
 			if !reflect.DeepEqual(tc.output, &output) {
 				t.Errorf("Expected output to be %v, but got %v", tc.output, output)
 			}
-			if !reflect.DeepEqual(tc.err, err) {
-				t.Errorf("Expected error to be %v, but got %v", tc.err, err)
-			}
+			assert.Equal(t, fmt.Sprintf("%v", err), fmt.Sprintf("%v", tc.err), "Expected error to be %v, but got %v", tc.err, err)
 		})
 	}
 }