github.com/tuhaihe/gpbackup@v1.0.3/integration/agent_remote_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/tuhaihe/gp-common-go-libs/cluster"
     7  	"github.com/tuhaihe/gpbackup/filepath"
     8  	"github.com/tuhaihe/gpbackup/utils"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("agent remote", func() {
    15  	var (
    16  		oidList     []string
    17  		filePath    filepath.FilePathInfo
    18  		testCluster *cluster.Cluster
    19  	)
    20  	BeforeEach(func() {
    21  		oidList = []string{"1", "2", "3"}
    22  		segConfig := cluster.MustGetSegmentConfiguration(connectionPool)
    23  		testCluster = cluster.NewCluster(segConfig)
    24  		filePath = filepath.NewFilePathInfo(testCluster, "my_dir", "20190102030405", filepath.GetSegPrefix(connectionPool))
    25  	})
    26  	Describe("WriteOidListToSegments()", func() {
    27  		It("writes oids to a temp file and copies it to all segments", func() {
    28  			utils.WriteOidListToSegments(oidList, testCluster, filePath, "oid")
    29  
    30  			remoteOutput := testCluster.GenerateAndExecuteCommand("ensure oid file was written to segments", cluster.ON_SEGMENTS, func(contentID int) string {
    31  				remoteOidFile := filePath.GetSegmentHelperFilePath(contentID, "oid")
    32  				return fmt.Sprintf("cat %s", remoteOidFile)
    33  			})
    34  			defer func() {
    35  				remoteOutputRemoval := testCluster.GenerateAndExecuteCommand("ensure oid file removed", cluster.ON_SEGMENTS, func(contentID int) string {
    36  					remoteOidFile := filePath.GetSegmentHelperFilePath(contentID, "oid")
    37  					return fmt.Sprintf("rm %s", remoteOidFile)
    38  				})
    39  				testCluster.CheckClusterError(remoteOutputRemoval, "Could not remove oid file", func(contentID int) string {
    40  					return "Could not remove oid file"
    41  				})
    42  			}()
    43  
    44  			testCluster.CheckClusterError(remoteOutput, "Could not cat oid file", func(contentID int) string {
    45  				return "Could not cat oid file"
    46  			})
    47  
    48  			for _, cmd := range remoteOutput.Commands {
    49  				Expect(cmd.Stdout).To(Equal("1\n2\n3\n"))
    50  			}
    51  		})
    52  	})
    53  })