Skip to content

Commit

Permalink
⏪ Restore file structure for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
katronquillo committed Nov 1, 2024
1 parent 70f1510 commit f4a7de2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
File renamed without changes.
32 changes: 21 additions & 11 deletions internal/controller/template_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path"
"path/filepath"
"slices"
"time"

sigyaml "sigs.k8s.io/yaml"
Expand Down Expand Up @@ -65,7 +66,8 @@ var _ = Describe("Template Controller Integration Test", func() {
Expect(err).NotTo(HaveOccurred())
for _, exampleFolder := range exampleFolders {
inputFolder := path.Join(exampleFolderPath, exampleFolder, "input")
applyYAMLFilesFromDirectory(ctx, inputFolder)
templateFolder := path.Join(inputFolder, "templates")
applyYAMLFilesFromDirectory(ctx, inputFolder, []string{templateFolder})
}
})

Expand All @@ -77,8 +79,6 @@ var _ = Describe("Template Controller Integration Test", func() {
for _, exampleFolder := range exampleFolders {
inputFolder := path.Join(exampleFolderPath, exampleFolder, "input")
deleteYAMLFilesFromDirectory(ctx, inputFolder)
templateFolder := path.Join(exampleFolderPath, exampleFolder, "templates")
deleteYAMLFilesFromDirectory(ctx, templateFolder)
}
})

Expand All @@ -92,8 +92,8 @@ var _ = Describe("Template Controller Integration Test", func() {
By(fmt.Sprintf("Running example %s", exampleFolder))

By("applying example templates")
templateFolder := path.Join(exampleFolderPath, exampleFolder, "templates")
applyYAMLFilesFromDirectory(ctx, templateFolder)
templateFolder := path.Join(exampleFolderPath, exampleFolder, "input", "templates")
applyYAMLFilesFromDirectory(ctx, templateFolder, nil)

By("verifying that the output.yaml file has been created")
verifyExampleOutput(path.Join(exampleFolderPath, exampleFolder), "out.yaml")
Expand All @@ -109,8 +109,8 @@ var _ = Describe("Template Controller Integration Test", func() {
By(fmt.Sprintf("Running example %s", exampleFolder))

By("applying example templates")
templateFolder := path.Join(exampleFolderPath, exampleFolder, "templates")
applyYAMLFilesFromDirectory(ctx, templateFolder)
templateFolder := path.Join(exampleFolderPath, exampleFolder, "input", "templates")
applyYAMLFilesFromDirectory(ctx, templateFolder, nil)

By("verifying that the output.yaml file has been created")
verifyExampleOutput(path.Join(exampleFolderPath, exampleFolder), "out.yaml")
Expand All @@ -125,8 +125,8 @@ var _ = Describe("Template Controller Integration Test", func() {
exampleFolders, err := utils.GetSubDirs(exampleFolderPath)
Expect(err).NotTo(HaveOccurred())
for _, exampleFolder := range exampleFolders {
templateFolder := path.Join(exampleFolderPath, exampleFolder, "templates")
applyYAMLFilesFromDirectory(ctx, templateFolder)
templateFolder := path.Join(exampleFolderPath, exampleFolder, "input", "templates")
applyYAMLFilesFromDirectory(ctx, templateFolder, nil)
}
})

Expand All @@ -137,7 +137,7 @@ var _ = Describe("Template Controller Integration Test", func() {

for _, exampleFolder := range exampleFolders {
By("deleting example template")
templateFolder := path.Join(exampleFolderPath, exampleFolder, "templates")
templateFolder := path.Join(exampleFolderPath, exampleFolder, "input", "templates")
deleteYAMLFilesFromDirectory(ctx, templateFolder)

By("verifying expected managed resources got deleted")
Expand Down Expand Up @@ -179,10 +179,20 @@ func getK8sClientObject(path string) (*unstructured.Unstructured, error) {
}

// Apply all YAML files defined in the given directory, dir, as well as all sub-directories
func applyYAMLFilesFromDirectory(ctx context.Context, dir string) {
// Ignores paths specified in excludePaths
func applyYAMLFilesFromDirectory(ctx context.Context, dir string, excludePaths []string) {
if excludePaths == nil {
excludePaths = []string{}
}

err := filepath.WalkDir(dir, func(path string, entry os.DirEntry, err error) error {
Expect(err).NotTo(HaveOccurred())

// Ignore paths specified in excludePaths
if slices.Contains(excludePaths, path) {
return filepath.SkipDir
}

// Entry is a YAML file - Apply manifest
if isYAMLFile(path) {
// Get K8s resource from YAML file
Expand Down

0 comments on commit f4a7de2

Please sign in to comment.