MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestBashPermissions

Function TestBashPermissions

internal/postgres/config_test.go:197–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

195}
196
197func TestBashPermissions(t *testing.T) {
198 // macOS `stat` takes different arguments than BusyBox and GNU coreutils.
199 if output, err := exec.CommandContext(t.Context(), "stat", "--help").CombinedOutput(); err != nil {
200 t.Skip(`requires "stat" executable`)
201 } else if !strings.Contains(string(output), "%A") {
202 t.Skip(`requires "stat" with access format sequence`)
203 }
204
205 dir := t.TempDir()
206 assert.NilError(t, os.Mkdir(filepath.Join(dir, "sub"), 0o751))
207 assert.NilError(t, os.Chmod(filepath.Join(dir, "sub"), 0o751))
208 assert.NilError(t, os.WriteFile(filepath.Join(dir, "sub", "fn"), nil, 0o624)) // #nosec G306 OK permissions for a temp dir in a test
209 assert.NilError(t, os.Chmod(filepath.Join(dir, "sub", "fn"), 0o624))
210
211 cmd := exec.CommandContext(t.Context(), "bash")
212 cmd.Args = append(cmd.Args, "-c", "--",
213 bashPermissions+`; permissions "$@"`, "-",
214 filepath.Join(dir, "sub", "fn"))
215
216 stdout, err := cmd.Output()
217 assert.NilError(t, err)
218 assert.Assert(t, cmp.Regexp(``+
219 `drwxr-x--x\s+\d+\s+\d+\s+[^ ]+/sub\n`+
220 `-rw--w-r--\s+\d+\s+\d+\s+[^ ]+/sub/fn\n`+
221 `$`, string(stdout)))
222}
223
224func TestBashRecreateDirectory(t *testing.T) {
225 // macOS `stat` takes different arguments than BusyBox and GNU coreutils.

Callers

nothing calls this directly

Calls 1

RegexpFunction · 0.92

Tested by

no test coverage detected