Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ type KnTest struct {

// NewKnTest creates a new KnTest object
func NewKnTest() (*KnTest, error) {
ns := NextNamespace()

err := CreateNamespace(ns)
if err != nil {
return nil, err
ns := ""
// try next 20 namespace before giving up creating a namespace if it already exists
for i := 0; i < 20; i++ {
ns = NextNamespace()
err := CreateNamespace(ns)
if err == nil {
break
}
if strings.Contains(err.Error(), "AlreadyExists") {
continue
} else {
return nil, err
}
}
err = WaitForNamespaceCreated(ns)

err := WaitForNamespaceCreated(ns)
if err != nil {
return nil, err
}
Expand Down
19 changes: 18 additions & 1 deletion lib/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@

package test

import "testing"
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

const (
FileModeReadWrite = 0666
FileModeExecutable = 0777
)

// GetResourceFieldsWithJSONPath returns output of given JSON path for given resource using kubectl and error if any
func GetResourceFieldsWithJSONPath(t *testing.T, it *KnTest, resource, name, jsonpath string) (string, error) {
Expand All @@ -25,3 +35,10 @@ func GetResourceFieldsWithJSONPath(t *testing.T, it *KnTest, resource, name, jso

return out, nil
}

// CreateFile creates a file with given name, content, path, fileMode and returns absolute filepath and error if any
func CreateFile(fileName, fileContent, filePath string, fileMode os.FileMode) (string, error) {
file := filepath.Join(filePath, fileName)
err := ioutil.WriteFile(file, []byte(fileContent), fileMode)
return file, err
}
21 changes: 7 additions & 14 deletions test/e2e/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

// +build e2e
// +build !eventing
// +build !serving

package e2e

Expand All @@ -35,9 +37,6 @@ const (
echo "Hello Knative, I'm a Kn plugin"
echo " My plugin file is $0"
echo " I received arguments: $1 $2 $3 $4"`

FileModeReadWrite = 0666
FileModeExecutable = 0777
)

type pluginTestConfig struct {
Expand All @@ -53,27 +52,27 @@ func (pc *pluginTestConfig) setup() error {
}

pc.knPluginsDir = filepath.Join(pc.knConfigDir, "plugins")
err = os.MkdirAll(pc.knPluginsDir, FileModeExecutable)
err = os.MkdirAll(pc.knPluginsDir, test.FileModeExecutable)
if err != nil {
return err
}

pc.knPluginsDir2 = filepath.Join(pc.knConfigDir, "plugins2")
err = os.MkdirAll(pc.knPluginsDir2, FileModeExecutable)
err = os.MkdirAll(pc.knPluginsDir2, test.FileModeExecutable)
if err != nil {
return err
}

pc.knConfigPath, err = createPluginFile("config.yaml", "", pc.knConfigDir, FileModeReadWrite)
pc.knConfigPath, err = test.CreateFile("config.yaml", "", pc.knConfigDir, test.FileModeReadWrite)
if err != nil {
return err
}

pc.knPluginPath, err = createPluginFile("kn-helloe2e", TestPluginCode, pc.knPluginsDir, FileModeExecutable)
pc.knPluginPath, err = test.CreateFile("kn-helloe2e", TestPluginCode, pc.knPluginsDir, test.FileModeExecutable)
if err != nil {
return err
}
pc.knPluginPath2, err = createPluginFile("kn-hello2e2e", TestPluginCode, pc.knPluginsDir2, FileModeExecutable)
pc.knPluginPath2, err = test.CreateFile("kn-hello2e2e", TestPluginCode, pc.knPluginsDir2, test.FileModeExecutable)
if err != nil {
return err
}
Expand All @@ -84,12 +83,6 @@ func (pc *pluginTestConfig) teardown() {
os.RemoveAll(pc.knConfigDir)
}

func createPluginFile(fileName, fileContent, filePath string, fileMode os.FileMode) (string, error) {
file := filepath.Join(filePath, fileName)
err := ioutil.WriteFile(file, []byte(fileContent), fileMode)
return file, err
}

func TestPluginWithoutLookup(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/sinkprefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (tc *sinkprefixTestConfig) setup() error {
if err != nil {
return err
}
tc.knConfigPath, err = createPluginFile("config.yaml", KnConfigContent, tc.knConfigDir, FileModeReadWrite)
tc.knConfigPath, err = test.CreateFile("config.yaml", KnConfigContent, tc.knConfigDir, test.FileModeReadWrite)
if err != nil {
return err
}
Expand Down