(t *testing.T)
| 49 | } |
| 50 | |
| 51 | func TestStartupCommand(t *testing.T) { |
| 52 | assert.Assert(t, cmp.MarshalMatches(startupCommand(), ` |
| 53 | - bash |
| 54 | - -ceu |
| 55 | - -- |
| 56 | - (umask a-w && echo "$1" > /etc/pgadmin/config_system.py) |
| 57 | - startup |
| 58 | - | |
| 59 | import glob, json, re, os |
| 60 | DEFAULT_BINARY_PATHS = {'pg': sorted([''] + glob.glob('/usr/pgsql-*/bin')).pop()} |
| 61 | with open('/etc/pgadmin/conf.d/~postgres-operator/pgadmin.json') as _f: |
| 62 | _conf, _data = re.compile(r'[A-Z_0-9]+'), json.load(_f) |
| 63 | if type(_data) is dict: |
| 64 | globals().update({k: v for k, v in _data.items() if _conf.fullmatch(k)}) |
| 65 | if os.path.isfile('/etc/pgadmin/conf.d/~postgres-operator/ldap-bind-password'): |
| 66 | with open('/etc/pgadmin/conf.d/~postgres-operator/ldap-bind-password') as _f: |
| 67 | LDAP_BIND_PASSWORD = _f.read() |
| 68 | `)) |
| 69 | |
| 70 | t.Run("ShellCheck", func(t *testing.T) { |
| 71 | command := startupCommand() |
| 72 | shellcheck := require.ShellCheck(t) |
| 73 | |
| 74 | assert.Assert(t, len(command) > 3) |
| 75 | dir := t.TempDir() |
| 76 | file := filepath.Join(dir, "script.bash") |
| 77 | assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600)) |
| 78 | |
| 79 | // Expect shellcheck to be happy. |
| 80 | cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file) |
| 81 | output, err := cmd.CombinedOutput() |
| 82 | assert.NilError(t, err, "%q\n%s", cmd.Args, output) |
| 83 | }) |
| 84 | |
| 85 | t.Run("ConfigSystemFlake8", func(t *testing.T) { |
| 86 | command := startupCommand() |
| 87 | flake8 := require.Flake8(t) |
| 88 | |
| 89 | assert.Assert(t, len(command) > 5) |
| 90 | dir := t.TempDir() |
| 91 | file := filepath.Join(dir, "script.py") |
| 92 | assert.NilError(t, os.WriteFile(file, []byte(command[5]), 0o600)) |
| 93 | |
| 94 | // Expect flake8 to be happy. Ignore "E401 multiple imports on one line" |
| 95 | // in addition to the defaults. The file contents appear in PodSpec, so |
| 96 | // allow lines longer than the default to save some vertical space. |
| 97 | cmd := exec.CommandContext(t.Context(), flake8, "--extend-ignore=E401", "--max-line-length=99", file) |
| 98 | output, err := cmd.CombinedOutput() |
| 99 | assert.NilError(t, err, "%q\n%s", cmd.Args, output) |
| 100 | }) |
| 101 | } |
| 102 | |
| 103 | func TestSystemSettings(t *testing.T) { |
| 104 | spec := new(v1beta1.PGAdminPodSpec) |
nothing calls this directly
no test coverage detected