go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/db/config_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package db
     9  
    10  import (
    11  	"context"
    12  	"testing"
    13  
    14  	. "go.charczuk.com/sdk/assert"
    15  )
    16  
    17  func Test_Config_Resolve(t *testing.T) {
    18  	var cfg Config
    19  	err := (&cfg).Resolve(context.Background())
    20  	ItsNil(t, err)
    21  
    22  	ItsEqual(t, DefaultEngine, cfg.Engine)
    23  }
    24  
    25  func Test_Config_CreateLoggingDSN(t *testing.T) {
    26  	cfg := Config{
    27  		Host:     "prod-db.cluster.local",
    28  		Port:     "5432",
    29  		Username: "bailey",
    30  		Password: "woofs123",
    31  		Database: "my-database",
    32  		SSLMode:  "require",
    33  	}
    34  	loggingDSN := cfg.CreateLoggingDSN()
    35  	ItsEqual(t, "postgres://bailey@prod-db.cluster.local:5432/my-database?sslmode=require", loggingDSN)
    36  }
    37  
    38  func Test_Config_CreateLoggingDSN_dsnSet(t *testing.T) {
    39  	cfg := Config{
    40  		DSN: "postgres://bailey:woofs123@prod-db.cluster.local:5432/my-database?sslmode=require",
    41  	}
    42  	loggingDSN := cfg.CreateLoggingDSN()
    43  	ItsEqual(t, "postgres://bailey@prod-db.cluster.local:5432/my-database?sslmode=require", loggingDSN)
    44  }