Add test to verify readonly mode
This commit is contained in:
parent
661fed0dbb
commit
2d2bd1d0b1
@ -232,7 +232,7 @@ func (client *Client) SetReadOnlyMode() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if value == "off" {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,6 +333,18 @@ func test_HistoryUniqueness(t *testing.T) {
|
|||||||
assert.Equal(t, "SELECT * FROM books WHERE id = 1", client.History[0].Query)
|
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) {
|
func TestAll(t *testing.T) {
|
||||||
if onWindows() {
|
if onWindows() {
|
||||||
// Dont have access to windows machines at the moment...
|
// Dont have access to windows machines at the moment...
|
||||||
@ -362,6 +374,7 @@ func TestAll(t *testing.T) {
|
|||||||
test_ResultCsv(t)
|
test_ResultCsv(t)
|
||||||
test_History(t)
|
test_History(t)
|
||||||
test_HistoryError(t)
|
test_HistoryError(t)
|
||||||
|
test_ReadOnlyMode(t)
|
||||||
|
|
||||||
teardownClient()
|
teardownClient()
|
||||||
teardown()
|
teardown()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user