From 4a93acb082df6670f1f31e7e14d540765e5babc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Wed, 16 Aug 2023 00:35:38 -0500 Subject: [PATCH] update sources on change (#167) --- dsnexec/pkg/dsnexec/dsnexec.go | 6 ++++++ dsnexec/pkg/dsnexec/dsnexec_test.go | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dsnexec/pkg/dsnexec/dsnexec.go b/dsnexec/pkg/dsnexec/dsnexec.go index 09b9bc36..e9f07d68 100644 --- a/dsnexec/pkg/dsnexec/dsnexec.go +++ b/dsnexec/pkg/dsnexec/dsnexec.go @@ -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) } diff --git a/dsnexec/pkg/dsnexec/dsnexec_test.go b/dsnexec/pkg/dsnexec/dsnexec_test.go index f23bb0c2..8e2a42e5 100644 --- a/dsnexec/pkg/dsnexec/dsnexec_test.go +++ b/dsnexec/pkg/dsnexec/dsnexec_test.go @@ -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), }, }, },