Skip to content

Commit

Permalink
add tests for probe DB URI
Browse files Browse the repository at this point in the history
  • Loading branch information
dm-2 committed Jan 24, 2023
1 parent 5899b99 commit 3e8b4d7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/mysql/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package mysql
import (
"testing"

"github.com/github/freno/pkg/config"
"github.com/outbrain/golib/log"
test "github.com/outbrain/golib/tests"
)
Expand Down Expand Up @@ -49,3 +50,19 @@ func TestDuplicate(t *testing.T) {
test.S(t).ExpectEquals(dup.User, "gromit")
test.S(t).ExpectEquals(dup.Password, "penguin")
}

func TestGetDBUri(t *testing.T) {
c := NewProbe()
c.Key = InstanceKey{Hostname: "myhost", Port: 3306}
c.User = "gromit"
c.Password = "penguin"

// test default (charset)
dbUri := c.GetDBUri("test_database")
test.S(t).ExpectEquals(dbUri, "gromit:penguin@tcp(myhost:3306)/test_database?interpolateParams=true&charset=utf8mb4,utf8,latin1&timeout=1000ms")

// test setting collation
config.Settings().Stores.MySQL.Collation = "utf8mb4_unicode_ci"
dbUri = c.GetDBUri("test_database")
test.S(t).ExpectEquals(dbUri, "gromit:penguin@tcp(myhost:3306)/test_database?interpolateParams=true&collation=utf8mb4_unicode_ci&timeout=1000ms")
}

0 comments on commit 3e8b4d7

Please sign in to comment.