-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retries, ping timeout, sql mock handler (#75)
retries
- Loading branch information
Showing
8 changed files
with
174 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
.vscode | ||
.idea/ | ||
*.iml | ||
|
||
mock-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package mock | ||
package csv | ||
|
||
import ( | ||
"errors" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"database/sql/driver" | ||
"encoding/json" | ||
"errors" | ||
"sync" | ||
|
||
"github.com/grafana/grafana-plugin-sdk-go/backend" | ||
) | ||
|
||
var pool *mockDriver | ||
|
||
func init() { | ||
func RegisterDriver(name string, handler DBHandler) *mockDriver { | ||
pool = &mockDriver{ | ||
conns: make(map[string]*sqlmock), | ||
conns: make(map[string]*sqlmock), | ||
handler: handler, | ||
} | ||
sql.Register("sqlmock", pool) | ||
sql.Register(name, pool) | ||
return pool | ||
} | ||
|
||
type DBHandler interface { | ||
Ping(ctx context.Context) error | ||
Query(args []driver.Value) (driver.Rows, error) | ||
Columns() []string | ||
Next(dest []driver.Value) error | ||
} | ||
|
||
type mockDriver struct { | ||
sync.Mutex | ||
counter int | ||
conns map[string]*sqlmock | ||
handler DBHandler | ||
} | ||
|
||
func (d *mockDriver) Open(dsn string) (driver.Conn, error) { | ||
if len(d.conns) == 0 { | ||
mock := &sqlmock{ | ||
drv: d, | ||
sleep: 10, | ||
drv: d, | ||
} | ||
d.conns = map[string]*sqlmock{ | ||
dsn: mock, | ||
} | ||
} | ||
return d.conns[dsn], nil | ||
} | ||
|
||
func (d *mockDriver) Connect(backend.DataSourceInstanceSettings, json.RawMessage) (db *sql.DB, err error) { | ||
return nil, errors.New("context deadline exceeded") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters