Skip to content

Commit

Permalink
Integration: fix example plugin integration test to use relative paths
Browse files Browse the repository at this point in the history
When gpbackup repo is not in $GOPATH and integration tests are run,
tests that use the example plugin will hang because the test cannot
proceed without the example plugin reading data from test pipes. This
happens because the example plugin and it's config file locations were
hardcoded to be in $GOPATH. This is a legacy issue from when go projects
were required to be in $GOPATH. This requirement was changed to be
optional in go1.11. This is an update to look for example plugin using a
relative path. The test plugin config file is also now setup before
tests run because the executablepath is also updated to be a relative
path.
  • Loading branch information
kyeap-vmware committed Feb 2, 2024
1 parent defa05d commit 0c22043
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
62 changes: 42 additions & 20 deletions integration/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"time"
Expand All @@ -21,15 +22,17 @@ import (
)

var (
testDir = "/tmp/helper_test/20180101/20180101010101"
pluginDir = "/tmp/plugin_dest/20180101/20180101010101"
tocFile = fmt.Sprintf("%s/test_toc.yaml", testDir)
oidFile = fmt.Sprintf("%s/test_oids", testDir)
pipeFile = fmt.Sprintf("%s/test_pipe", testDir)
dataFileFullPath = filepath.Join(testDir, "test_data")
pluginBackupPath = filepath.Join(pluginDir, "test_data")
errorFile = fmt.Sprintf("%s_error", pipeFile)
pluginConfigPath = fmt.Sprintf("%s/src/github.com/greenplum-db/gpbackup/plugins/example_plugin_config.yaml", os.Getenv("GOPATH"))
examplePluginExec string
examplePluginTestConfig = "/tmp/test_example_plugin_config.yaml"
examplePluginTestBackupDir = "/tmp/plugin_dest/20180101/20180101010101"
examplePluginTestDataFile = filepath.Join(examplePluginTestBackupDir, "test_data")
examplePluginTestDir = "/tmp/plugin_dest" // hardcoded in example plugin
testDir = "/tmp/helper_test/20180101/20180101010101"
tocFile = fmt.Sprintf("%s/test_toc.yaml", testDir)
oidFile = fmt.Sprintf("%s/test_oids", testDir)
pipeFile = fmt.Sprintf("%s/test_pipe", testDir)
dataFileFullPath = filepath.Join(testDir, "test_data")
errorFile = fmt.Sprintf("%s_error", pipeFile)
)

const (
Expand Down Expand Up @@ -73,14 +76,33 @@ func buildAndInstallBinaries() string {
}

var _ = Describe("gpbackup_helper end to end integration tests", func() {
// Setup example plugin based on current working directory
err := os.RemoveAll(examplePluginTestDir)
Expect(err).ToNot(HaveOccurred())
err = os.MkdirAll(examplePluginTestDir, 0777)
Expect(err).ToNot(HaveOccurred())
currentDir, err := os.Getwd()
Expect(err).ToNot(HaveOccurred())
rootDir := path.Dir(currentDir)
examplePluginExec = path.Join(rootDir, "plugins", "example_plugin.bash")
examplePluginTestConfigContents := fmt.Sprintf(`executablepath: %s
options:
password: unknown`, examplePluginExec)
f, err := os.Create(examplePluginTestConfig)
Expect(err).ToNot(HaveOccurred())
_, err = f.WriteString(examplePluginTestConfigContents)
Expect(err).ToNot(HaveOccurred())
err = f.Close()
Expect(err).ToNot(HaveOccurred())

BeforeEach(func() {
err := os.RemoveAll(testDir)
Expect(err).ToNot(HaveOccurred())
err = os.MkdirAll(testDir, 0777)
Expect(err).ToNot(HaveOccurred())
err = os.RemoveAll(pluginDir)
err = os.RemoveAll(examplePluginTestBackupDir)
Expect(err).ToNot(HaveOccurred())
err = os.MkdirAll(pluginDir, 0777)
err = os.MkdirAll(examplePluginTestBackupDir, 0777)
Expect(err).ToNot(HaveOccurred())

err = unix.Mkfifo(fmt.Sprintf("%s_%d", pipeFile, 1), 0777)
Expand Down Expand Up @@ -125,23 +147,23 @@ var _ = Describe("gpbackup_helper end to end integration tests", func() {
assertBackupArtifactsWithCompression("zstd", false)
})
It("runs backup gpbackup_helper without compression with plugin", func() {
helperCmd := gpbackupHelper(gpbackupHelperPath, "--backup-agent", "--compression-level", "0", "--data-file", dataFileFullPath, "--plugin-config", pluginConfigPath)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--backup-agent", "--compression-level", "0", "--data-file", dataFileFullPath, "--plugin-config", examplePluginTestConfig)
writeToPipes(defaultData)
err := helperCmd.Wait()
printHelperLogOnError(err)
Expect(err).ToNot(HaveOccurred())
assertBackupArtifacts(true)
})
It("runs backup gpbackup_helper with gzip compression with plugin", func() {
helperCmd := gpbackupHelper(gpbackupHelperPath, "--backup-agent", "--compression-type", "gzip", "--compression-level", "1", "--data-file", dataFileFullPath+".gz", "--plugin-config", pluginConfigPath)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--backup-agent", "--compression-type", "gzip", "--compression-level", "1", "--data-file", dataFileFullPath+".gz", "--plugin-config", examplePluginTestConfig)
writeToPipes(defaultData)
err := helperCmd.Wait()
printHelperLogOnError(err)
Expect(err).ToNot(HaveOccurred())
assertBackupArtifactsWithCompression("gzip", true)
})
It("runs backup gpbackup_helper with zstd compression with plugin", func() {
helperCmd := gpbackupHelper(gpbackupHelperPath, "--backup-agent", "--compression-type", "zstd", "--compression-level", "1", "--data-file", dataFileFullPath+".zst", "--plugin-config", pluginConfigPath)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--backup-agent", "--compression-type", "zstd", "--compression-level", "1", "--data-file", dataFileFullPath+".zst", "--plugin-config", examplePluginTestConfig)
writeToPipes(defaultData)
err := helperCmd.Wait()
printHelperLogOnError(err)
Expand Down Expand Up @@ -197,7 +219,7 @@ var _ = Describe("gpbackup_helper end to end integration tests", func() {
})
It("runs restore gpbackup_helper without compression with plugin", func() {
setupRestoreFiles("", true)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--restore-agent", "--data-file", dataFileFullPath, "--plugin-config", pluginConfigPath)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--restore-agent", "--data-file", dataFileFullPath, "--plugin-config", examplePluginTestConfig)
for _, i := range []int{1, 3} {
contents, _ := ioutil.ReadFile(fmt.Sprintf("%s_%d", pipeFile, i))
Expect(string(contents)).To(Equal("here is some data\n"))
Expand All @@ -209,7 +231,7 @@ var _ = Describe("gpbackup_helper end to end integration tests", func() {
})
It("runs restore gpbackup_helper with gzip compression with plugin", func() {
setupRestoreFiles("gzip", true)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--restore-agent", "--data-file", dataFileFullPath+".gz", "--plugin-config", pluginConfigPath)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--restore-agent", "--data-file", dataFileFullPath+".gz", "--plugin-config", examplePluginTestConfig)
for _, i := range []int{1, 3} {
contents, _ := ioutil.ReadFile(fmt.Sprintf("%s_%d", pipeFile, i))
Expect(string(contents)).To(Equal("here is some data\n"))
Expand All @@ -221,7 +243,7 @@ var _ = Describe("gpbackup_helper end to end integration tests", func() {
})
It("runs restore gpbackup_helper with zstd compression with plugin", func() {
setupRestoreFiles("zstd", true)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--restore-agent", "--data-file", dataFileFullPath+".zst", "--plugin-config", pluginConfigPath)
helperCmd := gpbackupHelper(gpbackupHelperPath, "--restore-agent", "--data-file", dataFileFullPath+".zst", "--plugin-config", examplePluginTestConfig)
for _, i := range []int{1, 3} {
contents, _ := ioutil.ReadFile(fmt.Sprintf("%s_%d", pipeFile, i))
Expect(string(contents)).To(Equal("here is some data\n"))
Expand Down Expand Up @@ -314,7 +336,7 @@ var _ = Describe("gpbackup_helper end to end integration tests", func() {
func setupRestoreFiles(compressionType string, withPlugin bool) {
dataFile := dataFileFullPath
if withPlugin {
dataFile = pluginBackupPath
dataFile = examplePluginTestDataFile
}

f, _ := os.Create(oidFile)
Expand Down Expand Up @@ -360,7 +382,7 @@ func assertBackupArtifacts(withPlugin bool) {
var err error
dataFile := dataFileFullPath
if withPlugin {
dataFile = pluginBackupPath
dataFile = examplePluginTestDataFile
}
contents, err = ioutil.ReadFile(dataFile)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -378,7 +400,7 @@ func assertBackupArtifactsWithCompression(compressionType string, withPlugin boo

dataFile := dataFileFullPath
if withPlugin {
dataFile = pluginBackupPath
dataFile = examplePluginTestDataFile
}

if compressionType == "gzip" {
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ var _ = AfterSuite(func() {
testhelper.AssertQueryRuns(connection1, "DROP ROLE anothertestrole")
connection1.Close()
_ = os.RemoveAll("/tmp/helper_test")
_ = os.RemoveAll("/tmp/plugin_dest")
_ = os.RemoveAll(examplePluginTestDir)
})

0 comments on commit 0c22043

Please sign in to comment.