mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
* Add accumulateResources error tests for local files. Add tests demonstrating accumulateResources errors when the resource is a local file. Works to address #4807. * Improve readability
38 lines
1008 B
Go
38 lines
1008 B
Go
// Copyright 2023 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package kusttest_test
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
|
)
|
|
|
|
// Setup sets up a file system on disk and directory that is cleaned after
|
|
// test completion.
|
|
func Setup(t *testing.T) (filesys.FileSystem, filesys.ConfirmedDir) {
|
|
t.Helper()
|
|
|
|
fSys := filesys.MakeFsOnDisk()
|
|
dir, err := filesys.NewTmpConfirmedDir()
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
_ = fSys.RemoveAll(dir.String())
|
|
})
|
|
return fSys, dir
|
|
}
|
|
|
|
// CreateKustDir creates a file system on disk and a new directory
|
|
// that holds a kustomization file with content. The directory is removed on
|
|
// test completion.
|
|
func CreateKustDir(t *testing.T, content string) (filesys.FileSystem, filesys.ConfirmedDir) {
|
|
t.Helper()
|
|
|
|
fSys, tmpDir := Setup(t)
|
|
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(content)))
|
|
return fSys, tmpDir
|
|
}
|