github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/testutil/postgrestestutil/init.go (about)

     1  package postgrestestutil
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/conf/app"
     7  	conflogger "github.com/machinefi/w3bstream/pkg/depends/conf/logger"
     8  	"github.com/machinefi/w3bstream/pkg/depends/conf/postgres"
     9  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx"
    10  )
    11  
    12  type TestEndpoint struct{ postgres.Endpoint }
    13  
    14  func (e *TestEndpoint) SetDefault() {
    15  	e.Endpoint.SetDefault()
    16  	if e.Master.Hostname == "" {
    17  		e.Master.Hostname = "127.0.0.1"
    18  	}
    19  	if e.Master.Base == "" {
    20  		e.Master.Base = "test"
    21  	}
    22  	if e.Master.Username == "" {
    23  		e.Master.Username = "test_user"
    24  	}
    25  	if e.Master.Password == "" {
    26  		e.Master.Password = "test_passwd"
    27  	}
    28  	if e.Slave.Hostname == "" {
    29  		e.Slave.Hostname = "localhost"
    30  	}
    31  	if e.Master.Param == nil {
    32  		e.Master.Param = make(url.Values)
    33  	}
    34  	e.Master.Param["sslmode"] = []string{"disable"}
    35  }
    36  
    37  var (
    38  	Endpoint = &TestEndpoint{Endpoint: postgres.Endpoint{Database: sqlx.NewDatabase("")}}
    39  )
    40  
    41  func init() {
    42  	app.New(
    43  		app.WithName("test"),
    44  		app.WithLogger(conflogger.Std()),
    45  		app.WithRoot("."),
    46  	).Conf(Endpoint)
    47  }