Skip to content

Commit

Permalink
move test out of temp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Apr 11, 2022
1 parent 4fdbebf commit 864b0e0
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -132,7 +132,7 @@ test-unit-all: \

# This target is used by our Github Actions CI to run unit tests for all non-plugin modules in multiple GOOS environments.
.PHONY: test-unit-non-plugin
test-unit-non-plugin:
test-unit-non-plugin: kustomize
./hack/for-each-module.sh "make test" "./plugin/*" 15

.PHONY: build-non-plugin-all
Expand Down
65 changes: 10 additions & 55 deletions api/krusty/fnplugin_test.go
Expand Up @@ -4,10 +4,10 @@
package krusty_test

import (
"bytes"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -639,61 +639,18 @@ metadata:
func TestFnContainerMounts(t *testing.T) {
skipIfNoDocker(t)

th := kusttest_test.MakeHarness(t)
o := th.MakeOptionsPluginsEnabled()
fSys := filesys.MakeFsOnDisk()
b := MakeKustomizer(&o)
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)

path, err := os.Getwd()
assert.NoError(t, err)

src := filepath.Join(path, "testdata", "charts") + string(filepath.Separator)
dst := filepath.Join(tmpDir.String(), "testdata", "charts") + string(filepath.Separator)
assert.NoError(t, os.MkdirAll(dst, 0777))

switch runtime.GOOS {
case "darwin":
cmd := exec.Command("cp", "-r", src, dst)
assert.NoError(t, cmd.Run())
case "linux":
d := dst + "."
cmd := exec.Command("cp", "-r", src, d)
assert.NoError(t, cmd.Run())
default:
t.SkipNow()
}
testDir := filepath.Join(path, "testdata", "fnmounts")
command := exec.Command("kustomize", "build", testDir, "--enable-alpha-plugins")
var stdout bytes.Buffer
var stderr bytes.Buffer
command.Stdout = &stdout
command.Stderr = &stderr
t.Log(stdout.String())

chartPath, err := filepath.Rel(tmpDir.String(), dst)
assert.NoError(t, err)

assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
generators:
- |-
apiVersion: v1alpha1
kind: RenderHelmChart
metadata:
name: demo
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/render-helm-chart:v0.1.0
mounts:
- type: "bind"
src: "`+chartPath+`"
dst: "/tmp/charts"
helmCharts:
- name: helloworld-chart
releaseName: test
valuesFile: /tmp/charts/helloworld-values/values.yaml
`)))
m, err := b.Run(
fSys,
tmpDir.String())
assert.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
assert.NoError(t, command.Run())
assert.Equal(t, `apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down Expand Up @@ -790,9 +747,7 @@ spec:
image: busybox
name: wget
restartPolicy: Never
`, string(yml))

assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
`, stdout.String())
}

func TestFnContainerMountsLoadRestrictions_absolute(t *testing.T) {
Expand Down
20 changes: 20 additions & 0 deletions api/krusty/testdata/fnmounts/kustomization.yaml
@@ -0,0 +1,20 @@
# Test file for TestFnContainerMounts

generators:
- |-
apiVersion: v1alpha1
kind: RenderHelmChart
metadata:
name: demo
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/render-helm-chart:v0.1.0
mounts:
- type: "bind"
src: "./charts"
dst: "/tmp/charts"
helmCharts:
- name: helloworld-chart
releaseName: test
valuesFile: /tmp/charts/helloworld-values/values.yaml

0 comments on commit 864b0e0

Please sign in to comment.