-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ligjn <[email protected]>
- Loading branch information
Showing
7 changed files
with
62 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ import ( | |
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore/kubeapi" | ||
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore/mongodb" | ||
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore/mysql" | ||
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore/opengauss" | ||
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore/postgres" | ||
) | ||
|
||
func initMysqlTestDs() (datastore.DataStore, error) { | ||
|
@@ -69,6 +69,28 @@ func initMysqlTestDs() (datastore.DataStore, error) { | |
return mysqlDriver, nil | ||
} | ||
|
||
func initPostgresTestDs() (datastore.DataStore, error) { | ||
db, err := gorm.Open(postgresorm.Open("postgres://postgres:[email protected]:5432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1"), &gorm.Config{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, v := range model.GetRegisterModels() { | ||
err := db.Migrator().DropTable(&v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
postgresDriver, err := postgres.New(context.TODO(), datastore.Config{ | ||
URL: "postgres://postgres:[email protected]:5432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1", | ||
Database: "kubevela", | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return postgresDriver, nil | ||
} | ||
|
||
// initOpenGaussTestDs Postgres Driver is also compatible with OpenGaussian databases | ||
func initOpenGaussTestDs() (datastore.DataStore, error) { | ||
db, err := gorm.Open(postgresorm.Open("postgres://gaussdb:[email protected]:15432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1"), &gorm.Config{}) | ||
if err != nil { | ||
|
@@ -80,7 +102,7 @@ func initOpenGaussTestDs() (datastore.DataStore, error) { | |
return nil, err | ||
} | ||
} | ||
openGaussDriver, err := opengauss.New(context.TODO(), datastore.Config{ | ||
openGaussDriver, err := postgres.New(context.TODO(), datastore.Config{ | ||
URL: "postgres://gaussdb:[email protected]:15432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1", | ||
Database: "kubevela", | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
*/ | ||
|
||
package opengauss | ||
package postgres | ||
|
||
import ( | ||
"context" | ||
|
@@ -26,15 +26,15 @@ import ( | |
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore" | ||
) | ||
|
||
func TestOpenGauss(t *testing.T) { | ||
func TestPostgres(t *testing.T) { | ||
_, err := New(context.TODO(), datastore.Config{ | ||
URL: "postgres://gaussdb:[email protected]:15432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1", | ||
URL: "postgres://postgres:[email protected]:5432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1", | ||
Database: "kubevela", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "OpenGauss Suite") | ||
RunSpecs(t, "Postgres Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package opengauss | ||
package postgres | ||
|
||
/* | ||
Copyright 2021 The KubeVela Authors. | ||
|
@@ -23,28 +23,28 @@ import ( | |
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
opengaussgorm "gorm.io/driver/postgres" | ||
postgresgorm "gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
|
||
"github.com/kubevela/velaux/pkg/server/domain/model" | ||
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore" | ||
) | ||
|
||
var opengaussDriver datastore.DataStore | ||
var postgresDriver datastore.DataStore | ||
var _ = BeforeSuite(func(ctx SpecContext) { | ||
rand.Seed(time.Now().UnixNano()) | ||
By("bootstrapping opengauss test environment") | ||
db, err := gorm.Open(opengaussgorm.Open("postgres://gaussdb:[email protected]:15432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1"), &gorm.Config{}) | ||
By("bootstrapping postgres test environment") | ||
db, err := gorm.Open(postgresgorm.Open("postgres://postgres:[email protected]:5432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1"), &gorm.Config{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
for _, v := range model.GetRegisterModels() { | ||
err := db.Migrator().DropTable(&v) | ||
Expect(err).ToNot(HaveOccurred()) | ||
} | ||
opengaussDriver, err = New(context.TODO(), datastore.Config{ | ||
URL: "postgres://gaussdb:[email protected]:15432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1", | ||
postgresDriver, err = New(context.TODO(), datastore.Config{ | ||
URL: "postgres://postgres:[email protected]:5432/kubevela?sslmode=disable&client_encoding=UTF-8&connect_timeout=1", | ||
Database: "kubevela", | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(opengaussDriver).ToNot(BeNil()) | ||
By("create opengauss driver success") | ||
Expect(postgresDriver).ToNot(BeNil()) | ||
By("create postgres driver success") | ||
}, NodeTimeout(2*time.Minute)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters