package mongo

import "testing"

func TestBuildConnectionURI_escapesPassword(t *testing.T) {
	t.Parallel()

	uri, err := buildConnectionURI(Conf{
		Schema:     "mongodb",
		Host:       "127.0.0.1:27017",
		User:       "user",
		Password:   "p@ss:word",
		AuthSource: "admin",
	})
	if err != nil {
		t.Fatal(err)
	}
	if uri != "mongodb://user:p%40ss%3Aword@127.0.0.1:27017?authSource=admin" {
		t.Fatalf("uri = %q", uri)
	}
}

func TestRedactConnectionURI(t *testing.T) {
	t.Parallel()

	raw := "mongodb://user:secret@127.0.0.1:27017"
	got := redactConnectionURI(raw)
	if got == raw {
		t.Fatalf("expected redacted uri, got %q", got)
	}
}
