Slide 45
Slide 45 text
© - BASE, Inc.
Extra Talk: configパッケージのユニットテスト全体
func TestNewConfig(t *testing.T) {
inputEnvs := map[string]string{
"MASTER_DB_HOST": "test_db_host",
"MASTER_DB_NAME": "test_db_name",
"MASTER_DB_USER": "test_db_user",
"MASTER_DB_PORT": "3306",
"MASTER_DB_PASSWORD": "test_db_password",
"MASTER_DB_SQL_MODE": "TEST_SQL_MODE",
}
restore := setEnvs(inputEnvs)
defer restore()
got, err := config.NewConfig()
if err != nil {
t.Fatalf("config.NewConfig got unexpected error %#v", err)
}
want := config.Config{
MasterDB: config.MasterDBConfig{
User: "test_db_user",
Password: "test_db_password",
Host: "test_db_host",
Name: "test_db_name",
Port: 3306,
SQLMode: "TEST_SQL_MODE",
},
}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("NewConfig() got differs: (-got +want)\n%s", diff)
}
}