You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by mi...@apache.org on 2023/04/23 09:52:08 UTC

[shardingsphere-on-cloud] branch main updated: chore(pitr): pitr agent add test workflow

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

miaoliyao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git


The following commit(s) were added to refs/heads/main by this push:
     new 8f4e60c  chore(pitr): pitr agent add test workflow
     new c4850c0  Merge pull request #320 from Xu-Wentao/pitr
8f4e60c is described below

commit 8f4e60ca81a63a172a6b874557bc183fcb64312d
Author: xuwentao <cu...@yahoo.com>
AuthorDate: Sun Apr 23 17:27:44 2023 +0800

    chore(pitr): pitr agent add test workflow
---
 .github/workflows/pitr-unit-test.yml      | 17 +++++++++++++++++
 pitr/agent/internal/pkg/opengauss.go      |  1 +
 pitr/agent/internal/pkg/opengauss_test.go |  4 ++++
 pitr/agent/internal/pkg/pkg_test.go       | 18 +++---------------
 pitr/agent/main.go                        | 14 +-------------
 pitr/agent/pkg/cmds/cmd_test.go           | 10 ++++++----
 pitr/agent/pkg/cmds/cmds_test.go          |  3 +++
 pitr/agent/pkg/gsutil/conn_test.go        | 27 ++++++++++++++++++++++++++-
 pitr/agent/pkg/logging/log.go             | 19 +++++++++++++++++--
 9 files changed, 78 insertions(+), 35 deletions(-)

diff --git a/.github/workflows/pitr-unit-test.yml b/.github/workflows/pitr-unit-test.yml
index 560f31f..f339f17 100644
--- a/.github/workflows/pitr-unit-test.yml
+++ b/.github/workflows/pitr-unit-test.yml
@@ -41,3 +41,20 @@ jobs:
         uses: codecov/codecov-action@v3
         with:
           files: ./pitr/cli/cover.out
+  pitr-agent:
+    runs-on: ubuntu-latest
+    steps:
+      - name: "checkout codes"
+        uses: actions/checkout@v3
+      - name: "setup go"
+        uses: actions/setup-go@v4
+        with:
+          go-version: '^1.18.1'
+      - name: "unit test"
+        run: |
+          cd pitr/agent
+          make test
+      - name: "Code coverage"
+        uses: codecov/codecov-action@v3
+        with:
+          files: ./pitr/agent/cover.out
diff --git a/pitr/agent/internal/pkg/opengauss.go b/pitr/agent/internal/pkg/opengauss.go
index 3db2ff8..0fd16b6 100644
--- a/pitr/agent/internal/pkg/opengauss.go
+++ b/pitr/agent/internal/pkg/opengauss.go
@@ -146,6 +146,7 @@ func (og *openGauss) ShowBackup(backupPath, instanceName, backupID string) (*mod
 	return nil, fmt.Errorf("backupList[v=%+v],err=%w", list, cons.DataNotFound)
 }
 
+// nolint
 func (og *openGauss) delBackup(backupPath, instanceName, backupID string) error {
 	cmd := fmt.Sprintf(_delBackupFmt, backupPath, instanceName, backupID)
 	_, err := cmds.Exec(og.shell, cmd)
diff --git a/pitr/agent/internal/pkg/opengauss_test.go b/pitr/agent/internal/pkg/opengauss_test.go
index 19f8b15..ad3f7ab 100644
--- a/pitr/agent/internal/pkg/opengauss_test.go
+++ b/pitr/agent/internal/pkg/opengauss_test.go
@@ -33,6 +33,7 @@ import (
 var _ = Describe("OpenGauss,requires opengauss environment", func() {
 	Context("AsyncBackup & ShowBackupDetail ", func() {
 		It("backup, show and delete", func() {
+			Skip("")
 			og := &openGauss{
 				shell:  "/bin/sh",
 				pgData: "/data/opengauss/3.1.1/data/single_node/",
@@ -85,6 +86,7 @@ var _ = Describe("OpenGauss,requires opengauss environment", func() {
 
 	Context("Init and deinit", func() {
 		It("Init backup and clean up the env", func() {
+			Skip("")
 			og := &openGauss{
 				shell: "/bin/sh",
 				log:   log,
@@ -125,6 +127,7 @@ var _ = Describe("OpenGauss,requires opengauss environment", func() {
 
 	Context("AddInstance and DelInstance", func() {
 		It("instance:add and delete", func() {
+			Skip("")
 			og := &openGauss{
 				shell:  "/bin/sh",
 				pgData: "/data/opengauss/3.1.1/data/single_node/",
@@ -151,6 +154,7 @@ var _ = Describe("OpenGauss,requires opengauss environment", func() {
 
 	Context("Start and Stop", func() {
 		It("start and stop:may fail if no instance exists", func() {
+			Skip("")
 			og := &openGauss{
 				shell:  "/bin/sh",
 				pgData: "/data/opengauss/3.1.1/data/single_node/",
diff --git a/pitr/agent/internal/pkg/pkg_test.go b/pitr/agent/internal/pkg/pkg_test.go
index d42e6fd..3cc07ac 100644
--- a/pitr/agent/internal/pkg/pkg_test.go
+++ b/pitr/agent/internal/pkg/pkg_test.go
@@ -18,11 +18,10 @@
 package pkg
 
 import (
-	"fmt"
+	"testing"
+
 	"github.com/apache/shardingsphere-on-cloud/pitr/agent/pkg/logging"
 	"go.uber.org/zap"
-	"go.uber.org/zap/zapcore"
-	"testing"
 
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
@@ -31,18 +30,7 @@ import (
 var log logging.ILog
 
 func init() {
-	prodConfig := zap.NewProductionConfig()
-	prodConfig.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
-	prodConfig.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
-	logger, err := prodConfig.Build(
-		zap.AddCallerSkip(1),
-		zap.AddStacktrace(zapcore.FatalLevel),
-	)
-	if err != nil {
-		panic(fmt.Errorf("an unknown error occured in the zap-log"))
-	}
-
-	log = logging.Init(logger)
+	log = logging.Init(zap.DebugLevel)
 }
 
 func TestPkg(t *testing.T) {
diff --git a/pitr/agent/main.go b/pitr/agent/main.go
index fcecc73..9279e25 100644
--- a/pitr/agent/main.go
+++ b/pitr/agent/main.go
@@ -32,7 +32,6 @@ import (
 	"github.com/apache/shardingsphere-on-cloud/pitr/agent/pkg/responder"
 	"github.com/gofiber/fiber/v2"
 	"github.com/joho/godotenv"
-	"go.uber.org/zap"
 	"go.uber.org/zap/zapcore"
 )
 
@@ -116,18 +115,7 @@ func main() {
 		level = zapcore.DebugLevel
 	}
 
-	prodConfig := zap.NewProductionConfig()
-	prodConfig.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
-	prodConfig.Level = zap.NewAtomicLevelAt(level)
-	logger, err := prodConfig.Build(
-		zap.AddCallerSkip(1),
-		zap.AddStacktrace(zapcore.FatalLevel),
-	)
-	if err != nil {
-		panic(fmt.Errorf("an unknown error occurred in the zap-log"))
-	}
-
-	log = logging.Init(logger)
+	log = logging.Init(level)
 	pkg.Init(shell, pgData, log)
 	app = fiber.New()
 
diff --git a/pitr/agent/pkg/cmds/cmd_test.go b/pitr/agent/pkg/cmds/cmd_test.go
index 55cd053..13e86a8 100644
--- a/pitr/agent/pkg/cmds/cmd_test.go
+++ b/pitr/agent/pkg/cmds/cmd_test.go
@@ -56,15 +56,17 @@ var _ = Describe("Commands", func() {
 
 	Context("test loadArgs", func() {
 		It("test reload gs_probackup", func() {
-			new := "/bin/new/gs_probackup"
-			os.Setenv("gs_probackup", new)
+			newGS := "/bin/new/gs_probackup"
+			err := os.Setenv("gs_probackup", newGS)
+			Expect(err).To(BeNil())
+
 			defer os.Unsetenv("gs_probackup")
 
 			args := loadArgs("gs_probackup", "backup", "-B", "/tmp", "-b", "FULL", "-D", "/tmp")
-			Expect(args[0]).To(Equal(new))
+			Expect(args[0]).To(Equal(newGS))
 
 			args = loadArgs("gs_probackup backup -B /tmp -b FULL -D /tmp")
-			Expect(strings.HasPrefix(args[0], new)).To(Equal(true))
+			Expect(strings.HasPrefix(args[0], newGS)).To(Equal(true))
 		})
 	})
 })
diff --git a/pitr/agent/pkg/cmds/cmds_test.go b/pitr/agent/pkg/cmds/cmds_test.go
index d39b5e2..758c6ea 100644
--- a/pitr/agent/pkg/cmds/cmds_test.go
+++ b/pitr/agent/pkg/cmds/cmds_test.go
@@ -20,11 +20,14 @@ package cmds
 import (
 	"testing"
 
+	"github.com/apache/shardingsphere-on-cloud/pitr/agent/pkg/logging"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
+	"go.uber.org/zap"
 )
 
 func TestCmds(t *testing.T) {
+	logging.Init(zap.DebugLevel)
 	RegisterFailHandler(Fail)
 	RunSpecs(t, "Cmds suits")
 }
diff --git a/pitr/agent/pkg/gsutil/conn_test.go b/pitr/agent/pkg/gsutil/conn_test.go
index 4dace0d..03e0c07 100644
--- a/pitr/agent/pkg/gsutil/conn_test.go
+++ b/pitr/agent/pkg/gsutil/conn_test.go
@@ -22,10 +22,17 @@ import (
 	. "github.com/onsi/gomega"
 )
 
+const (
+	user     = "dba3"
+	password = "1234567890@ss"
+	dbName   = "test-db"
+)
+
 var _ = Describe("OpenGauss", func() {
 	Context("Connection", func() {
 		It("Open and ping", func() {
-			og, err := Open("dba3", "1234567890@ss", "school", uint16(5432))
+			Skip("Skip this test case, because it needs a real OpenGauss server.")
+			og, err := Open(user, password, dbName, uint16(5432))
 			Expect(err).To(BeNil())
 			Expect(og).NotTo(BeNil())
 
@@ -33,4 +40,22 @@ var _ = Describe("OpenGauss", func() {
 			Expect(err).To(BeNil())
 		})
 	})
+
+	Context("check params", func() {
+		It("user is empty", func() {
+			og, err := Open("", password, dbName, uint16(5432))
+			Expect(err).NotTo(BeNil())
+			Expect(og).To(BeNil())
+		})
+		It("password is empty", func() {
+			og, err := Open(user, "", dbName, uint16(5432))
+			Expect(err).NotTo(BeNil())
+			Expect(og).To(BeNil())
+		})
+		It("database is empty", func() {
+			og, err := Open(user, password, "", uint16(5432))
+			Expect(err).NotTo(BeNil())
+			Expect(og).To(BeNil())
+		})
+	})
 })
diff --git a/pitr/agent/pkg/logging/log.go b/pitr/agent/pkg/logging/log.go
index 0505bd4..c5dd5cc 100644
--- a/pitr/agent/pkg/logging/log.go
+++ b/pitr/agent/pkg/logging/log.go
@@ -17,7 +17,12 @@
 
 package logging
 
-import "go.uber.org/zap"
+import (
+	"fmt"
+
+	"go.uber.org/zap"
+	"go.uber.org/zap/zapcore"
+)
 
 var l *ZapLogger
 
@@ -25,7 +30,17 @@ func Log() ILog {
 	return l
 }
 
-func Init(logger *zap.Logger) ILog {
+func Init(level zapcore.Level) ILog {
+	prodConfig := zap.NewProductionConfig()
+	prodConfig.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
+	prodConfig.Level = zap.NewAtomicLevelAt(level)
+	logger, err := prodConfig.Build(
+		zap.AddCallerSkip(1),
+		zap.AddStacktrace(zapcore.FatalLevel),
+	)
+	if err != nil {
+		panic(fmt.Errorf("an unknown error occurred in the zap-log"))
+	}
 	l = &ZapLogger{logger: logger}
 	return l
 }