mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-14 19:21:46 +03:00
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" {
|
||||
_, err = client.db.Exec("SET default_transaction_read_only=on;")
|
||||
_, err := client.db.Exec("SET default_transaction_read_only=on;")
|
||||
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)
|
||||
}
|
||||
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user