package main

import (
	"bytes"

	c "github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-check"
	"github.com/flynn/flynn/pkg/exec"
)

type PostgresSuite struct {
	Helper
}

var _ = c.ConcurrentSuite(&PostgresSuite{})

// Check postgres config to avoid regressing on https://github.com/flynn/flynn/issues/101
func (s *PostgresSuite) TestSSLRenegotiationLimit(t *c.C) {
	pgRelease, err := s.controllerClient(t).GetAppRelease("postgres")
	t.Assert(err, c.IsNil)

	cmd := exec.Command(exec.DockerImage(imageURIs["postgresql"]),
		"--tuples-only", "--command", "show ssl_renegotiation_limit;")
	cmd.Entrypoint = []string{"psql"}
	cmd.Env = map[string]string{
		"PGDATABASE": "postgres",
		"PGHOST":     "leader.pg.discoverd",
		"PGUSER":     "flynn",
		"PGPASSWORD": pgRelease.Env["PGPASSWORD"],
	}

	res, err := cmd.CombinedOutput()
	t.Assert(err, c.IsNil)
	t.Assert(string(bytes.TrimSpace(res)), c.Equals, "0")
}

package main

import (
	c "github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-check"
)

type PostgresSuite struct {
	Helper
}

var _ = c.ConcurrentSuite(&PostgresSuite{})

// Check postgres config to avoid regressing on https://github.com/flynn/flynn/issues/101
func (s *PostgresSuite) TestSSLRenegotiationLimit(t *c.C) {
	query := flynn(t, "/", "-a", "controller", "psql", "-c", "SHOW ssl_renegotiation_limit")
	t.Assert(query, Succeeds)
	t.Assert(query, OutputContains, "ssl_renegotiation_limit \n-------------------------\n 0\n(1 row)")
}

Use `flynn psql` for TestSSLRenegotiationLimit
test: Use `flynn psql` for TestSSLRenegotiationLimit

This avoids reimplementing the psql run logic in two places and tests
`flynn psql`.

Signed-off-by: Jonathan Rudenberg <3692bfa45759a67d83aedf0045f6cb635a966abf@titanous.com>
