Skip to content

Commit

Permalink
fix: reworks test for DirFS
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszmajsak committed Dec 18, 2023
1 parent a9f7b65 commit ab6d573
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
6 changes: 2 additions & 4 deletions pkg/feature/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ type manifest struct {
processedContent string
}

func loadManifestsFrom(fsys fs.FS, rootPath string) ([]manifest, error) {
func loadManifestsFrom(fsys fs.FS, path string) ([]manifest, error) {
var manifests []manifest

err := fs.WalkDir(fsys, rootPath, func(path string, dirEntry fs.DirEntry, err error) error {
err := fs.WalkDir(fsys, path, func(path string, dirEntry fs.DirEntry, err error) error {
if err != nil {
log.Error(err, "Failed to walk path", "path", path)
return err
}

Expand All @@ -44,7 +43,6 @@ func loadManifestsFrom(fsys fs.FS, rootPath string) ([]manifest, error) {

_, err = fs.ReadFile(fsys, path)
if err != nil {
log.Error(err, "Failed to load manifest from", "path", path)
return err
}
m := loadManifestFrom(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package servicemesh_test
import (
"context"
"embed"
log "github.com/sirupsen/logrus"
"io"
"os"
"path"
Expand Down Expand Up @@ -402,7 +401,7 @@ var _ = Describe("Alternate Manifest source", func() {
serviceMeshSpec.ControlPlane.Namespace = namespace
})

It("should be able to use different embedded manifests", func() {
FIt("should be able to use different embedded manifests", func() {
// given
ns := createNamespace(namespace)
Expect(envTestClient.Create(context.Background(), ns)).To(Succeed())
Expand Down Expand Up @@ -450,16 +449,15 @@ var _ = Describe("Alternate Manifest source", func() {
serviceMeshSpec.Auth.Namespace = "test-provider"
serviceMeshSpec.Auth.Authorino.Name = "authorino"

join := path.Join(feature.AuthDir, "mesh-authz-ext-provider.patch.tmpl")
myPath := moveTmplTo(tempDir, join)
log.Info("path is: ", myPath)
patchTemplate := path.Join(feature.AuthDir, "mesh-authz-ext-provider.patch.tmpl")
copyEmbeddedTemplatesTo(tempDir, patchTemplate)

createServiceMeshControlPlane(name, namespace)

controlPlaneWithExtAuthzProvider, err := feature.CreateFeature("external-manifests-control-plane-with-external-authz-provider").
For(dsciSpec).
ManifestSource(os.DirFS("/")).
Manifests(myPath).
ManifestSource(os.DirFS(tempDir)).
Manifests(patchTemplate). // must be relative to root DirFS defined above
UsingConfig(envTest.Config).
Load()

Expand Down Expand Up @@ -602,17 +600,15 @@ func getNamespace(namespace string) (*v1.Namespace, error) {
return ns, err
}

func moveTmplTo(tmpDir, fileName string) string {
func copyEmbeddedTemplatesTo(tmpDir, templatePath string) {
root, err := envtestutil.FindProjectRoot()
Expect(err).ToNot(HaveOccurred())

src := path.Join(root, "pkg", "feature", fileName)
dest := path.Join(tmpDir, fileName)
src := path.Join(root, "pkg", "feature", templatePath)
dest := path.Join(tmpDir, templatePath)
if err := copyFile(src, dest); err != nil {
Fail(err.Error())
}

return dest
}

func copyFile(src, dst string) error {
Expand Down

0 comments on commit ab6d573

Please sign in to comment.