Skip to content

Commit

Permalink
♻️ Change function name for clarity and use BeforeEach instead of Jus…
Browse files Browse the repository at this point in the history
…tBeforeEach
  • Loading branch information
katronquillo committed Nov 15, 2024
1 parent f4a7de2 commit 6f104d2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions internal/controller/template_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var _ = Describe("Template Controller Integration Test", func() {
for _, exampleFolder := range exampleFolders {
inputFolder := path.Join(exampleFolderPath, exampleFolder, "input")
templateFolder := path.Join(inputFolder, "templates")
applyYAMLFilesFromDirectory(ctx, inputFolder, []string{templateFolder})
applyResourcesFromYAMLInDir(ctx, inputFolder, []string{templateFolder})
}
})

Expand All @@ -78,7 +78,7 @@ var _ = Describe("Template Controller Integration Test", func() {
Expect(err).NotTo(HaveOccurred())
for _, exampleFolder := range exampleFolders {
inputFolder := path.Join(exampleFolderPath, exampleFolder, "input")
deleteYAMLFilesFromDirectory(ctx, inputFolder)
deleteResourcesFromYAMLInDir(ctx, inputFolder)
}
})

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

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

By("verifying that the output.yaml file has been created")
verifyExampleOutput(path.Join(exampleFolderPath, exampleFolder), "out.yaml")
Expand All @@ -110,7 +110,7 @@ var _ = Describe("Template Controller Integration Test", func() {

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

By("verifying that the output.yaml file has been created")
verifyExampleOutput(path.Join(exampleFolderPath, exampleFolder), "out.yaml")
Expand All @@ -119,14 +119,14 @@ var _ = Describe("Template Controller Integration Test", func() {
})

Context("When Template is deleted", func() {
JustBeforeEach(func() {
BeforeEach(func() {
By("applying example templates")
exampleFolderPath := path.Join("../", "../", "examples")
exampleFolders, err := utils.GetSubDirs(exampleFolderPath)
Expect(err).NotTo(HaveOccurred())
for _, exampleFolder := range exampleFolders {
templateFolder := path.Join(exampleFolderPath, exampleFolder, "input", "templates")
applyYAMLFilesFromDirectory(ctx, templateFolder, nil)
applyResourcesFromYAMLInDir(ctx, templateFolder, nil)
}
})

Expand All @@ -138,7 +138,7 @@ var _ = Describe("Template Controller Integration Test", func() {
for _, exampleFolder := range exampleFolders {
By("deleting example template")
templateFolder := path.Join(exampleFolderPath, exampleFolder, "input", "templates")
deleteYAMLFilesFromDirectory(ctx, templateFolder)
deleteResourcesFromYAMLInDir(ctx, templateFolder)

By("verifying expected managed resources got deleted")
expectedOutputPath := path.Join(exampleFolderPath, exampleFolder, "expected", "out.yaml")
Expand Down Expand Up @@ -178,9 +178,9 @@ func getK8sClientObject(path string) (*unstructured.Unstructured, error) {
return obj, nil
}

// Apply all YAML files defined in the given directory, dir, as well as all sub-directories
// Apply all resources specified by the YAML files in the given directory, dir, as well as all sub-directories
// Ignores paths specified in excludePaths
func applyYAMLFilesFromDirectory(ctx context.Context, dir string, excludePaths []string) {
func applyResourcesFromYAMLInDir(ctx context.Context, dir string, excludePaths []string) {
if excludePaths == nil {
excludePaths = []string{}
}
Expand Down Expand Up @@ -231,8 +231,8 @@ func waitForDeletion(ctx context.Context, obj *unstructured.Unstructured, timeou
}, timeout, interval).Should(Succeed())
}

// Delete all YAML files defined in the given directory, dir, as well as all sub-directories
func deleteYAMLFilesFromDirectory(ctx context.Context, dir string) {
// Delete all resources specified by the YAML files in the given directory, dir, as well as all sub-directories
func deleteResourcesFromYAMLInDir(ctx context.Context, dir string) {
err := filepath.WalkDir(dir, func(path string, entry os.DirEntry, err error) error {
Expect(err).NotTo(HaveOccurred())

Expand Down

0 comments on commit 6f104d2

Please sign in to comment.