Add test to verify readonly mode

This commit is contained in:
Dan Sosedoff 2016-11-05 17:51:34 -05:00
parent 661fed0dbb
commit 2d2bd1d0b1
2 changed files with 14 additions and 1 deletions

View File

@ -232,7 +232,7 @@ func (client *Client) SetReadOnlyMode() error {
}
if value == "off" {
_, err = client.db.Exec("SET default_transaction_read_only=on;")
_, err := client.db.Exec("SET default_transaction_read_only=on;")
return err
}

View File

@ -333,6 +333,18 @@ func test_HistoryUniqueness(t *testing.T) {
assert.Equal(t, "SELECT * FROM books WHERE id = 1", client.History[0].Query)
}
func test_ReadOnlyMode(t *testing.T) {
url := fmt.Sprintf("postgres://%s@%s:%s/%s?sslmode=disable", serverUser, serverHost, serverPort, serverDatabase)
client, _ := NewFromUrl(url, nil)
err := client.SetReadOnlyMode()
assert.Equal(t, nil, err)
_, err = client.Query("CREATE TABLE foobar(id integer);")
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "in a read-only transaction")
}
func TestAll(t *testing.T) {
if onWindows() {
// Dont have access to windows machines at the moment...
@ -362,6 +374,7 @@ func TestAll(t *testing.T) {
test_ResultCsv(t)
test_History(t)
test_HistoryError(t)
test_ReadOnlyMode(t)
teardownClient()
teardown()