Files
odo/tests/integration/plugin_handler_test.go
Armel Soro 7b9f214299 Bump Go to 1.19 (#6586)
* Set Go version in go.mod

go mod edit -go=1.19

* Fix formatting issues reported by gofmt

* Fix SA1019 check (usage of deprecated "io/ioutil"), reported by golangci-lint

SA1019: "io/ioutil" has been deprecated since Go 1.16:
As of Go 1.16, the same functionality is now provided by package io or package os,
and those implementations should be preferred in new code.
See the specific function documentation for details. (staticcheck)

* Use Go 1.19 in our Dockerfiles

* Use Go 1.19 in the rpm-prepare.sh script

* Update the tag for the IBM Cloud CI image
2023-02-16 09:03:48 -05:00

63 lines
1.5 KiB
Go

package integration
import (
"fmt"
"os"
"path"
"path/filepath"
"runtime"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redhat-developer/odo/pkg/odo/cli/plugins"
)
var sampleScript = []byte(`
#!/bin/sh
echo 'hello'
`)
var _ = Describe("odo plugin functionality", func() {
var tempDir string
var origPath = os.Getenv("PATH")
var handler plugins.PluginHandler
var _ = BeforeEach(func() {
var err error
tempDir, err = os.MkdirTemp(os.TempDir(), "odo")
Expect(err).NotTo(HaveOccurred())
os.Setenv("PATH", fmt.Sprintf("%s:%s", origPath, tempDir))
var baseScriptName = "tst-script"
scriptName := path.Join(tempDir, baseScriptName)
err = os.WriteFile(scriptName, sampleScript, 0755)
Expect(err).NotTo(HaveOccurred())
handler = plugins.NewExecHandler("tst")
})
var _ = AfterEach(func() {
err := os.RemoveAll(tempDir)
Expect(err).NotTo(HaveOccurred())
os.Setenv("PATH", origPath)
})
Context("when an executable with the correct prefix exists on the path", func() {
It("finds the plugin", func() {
if runtime.GOOS == "windows" {
Skip("doesn't find scripts on Windows platform")
}
found := handler.Lookup("script")
Expect(found).Should(Equal(filepath.Join(tempDir, "tst-script")))
})
})
Context("when no executable with the correct prefix exists on the path", func() {
It("does not find the plugin", func() {
if runtime.GOOS == "windows" {
Skip("doesn't find scripts on Windows platform")
}
found := handler.Lookup("unknown")
Expect(found).Should(Equal(""))
})
})
})