Skip to content

Commit

Permalink
update sources on change (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-garcia authored Aug 16, 2023
1 parent 025fe6c commit 4a93acb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions dsnexec/pkg/dsnexec/dsnexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func (w *Handler) UpdateDSN(path, content string) error {
w.l.RLock()
defer w.l.RUnlock()

// update the local state
w.config.Sources[path] = DBConnInfo{
Driver: w.config.Sources[path].Driver,
DSN: content,
}

if err := w.exec(); err != nil {
return fmt.Errorf("failed initial execute: %v", err)
}
Expand Down
8 changes: 6 additions & 2 deletions dsnexec/pkg/dsnexec/dsnexec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ func TestHandler_UpdateDSN(t *testing.T) {
},
},
},
args: args{
path: "test",
content: "postgres://user:pass@myhost:1234/dbname?sslmode=disable",
},
expectedExecCalls: []tdb.ExecArgs{
{
Query: "select 1",
Args: []driver.Value{
"localhost",
int64(5432),
"myhost",
int64(1234),
},
},
},
Expand Down

0 comments on commit 4a93acb

Please sign in to comment.