Skip to content

Commit

Permalink
fail if no files found matching include directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Frankie Gallina-Jones authored and arjun024 committed Apr 1, 2021
1 parent c1d1123 commit 3744a12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/configure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func getIncludedConfs(confText string, confDir string) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("failed to get 'include' files for %s: %w", conf, err)
}

if len(matchFiles) == 0 {
return nil, fmt.Errorf("failed to get 'include' files for %s: no matching files exist", conf)
}

includeFiles = append(includeFiles, matchFiles...)
}
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/configure/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,21 @@ http {
Expect(buffer.String()).To(ContainSubstring(`/\/\/.conf: syntax error in pattern`))
})
})
context("when an include file does not exist", func() {
it.Before(func() {
Expect(ioutil.WriteFile(filepath.Join(workingDir, "nginx.conf"), []byte("include donotexist.conf;"), 0644)).To(Succeed())
command = exec.Command(path, filepath.Join(workingDir, "nginx.conf"), localModulePath, globalModulePath)
buffer = bytes.NewBuffer(nil)
})

it("exits non-zero", func() {
session, err := gexec.Start(command, buffer, buffer)
Expect(err).ToNot(HaveOccurred())
Eventually(session).Should(gexec.Exit(1), buffer.String)
Expect(buffer.String()).To(ContainSubstring(`failed to get 'include' files for /tmp/working-dir`))
Expect(buffer.String()).To(ContainSubstring("no matching files exist"))
})
})
})
}, spec.Report(report.Terminal{}))
}

0 comments on commit 3744a12

Please sign in to comment.