Skip to content

Commit

Permalink
v0.0.4-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
yangkenneth committed Oct 19, 2023
1 parent c9d5580 commit 2ef8f2d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 68 deletions.
File renamed without changes.
53 changes: 53 additions & 0 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ package config
import (
"errors"
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/coinbase/baseca/internal/logger"
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
"go.uber.org/zap"
)

const (
_test_configuration = "config.test.local.sandbox.yml"
)

type configProvider struct {
v *viper.Viper
}
Expand Down Expand Up @@ -70,3 +77,49 @@ func (cp *configProvider) Get(path string, cfg any) error {
func (cp *configProvider) Exists(path string) bool {
return cp.v.Get(path) != nil
}

func GetTestConfigurationPath() (*Config, error) {
_, filename, _, ok := runtime.Caller(0)
if !ok {
fmt.Println("Error: Unable to get current file path")
}

baseDir := filepath.Dir(filename)
for {
if _, err := os.Stat(filepath.Join(baseDir, "go.mod")); err == nil {
break
}

parentDir := filepath.Dir(baseDir)
if parentDir == baseDir {
fmt.Println("Error: Unable to find base directory")
break
}

baseDir = parentDir
}

path := fmt.Sprintf("%s/config/%s", baseDir, _test_configuration)
fmt.Println("Loading configuration from path: " + path)
config, err := provideConfig(path)
if err != nil {
return nil, err
}
return config, nil
}

func provideConfig(path string) (*Config, error) {
ctxLogger := logger.ContextLogger{Logger: logger.DefaultLogger}

v, err := BuildViper(path)
if err != nil {
ctxLogger.Error(err.Error())
}

config, err := LoadConfig(v)
if err != nil {
return nil, err
}

return config, err
}
4 changes: 2 additions & 2 deletions internal/v1/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package accounts
import (
mock_store "github.com/coinbase/baseca/db/mock"
db "github.com/coinbase/baseca/db/sqlc"
"github.com/coinbase/baseca/internal/config"
"github.com/coinbase/baseca/internal/lib/util/validator"
"github.com/coinbase/baseca/test"
)

func buildAccountsConfig(store *mock_store.MockStore) (*Service, error) {
config, err := test.GetTestConfigurationPath()
config, err := config.GetTestConfigurationPath()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/certificate/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
acm_pca "github.com/coinbase/baseca/internal/client/acmpca"
"github.com/coinbase/baseca/internal/client/firehose"
redis_client "github.com/coinbase/baseca/internal/client/redis"
"github.com/coinbase/baseca/internal/config"
"github.com/coinbase/baseca/internal/lib/util/validator"
"github.com/coinbase/baseca/test"
"github.com/go-redis/redis/v8"
"github.com/stretchr/testify/mock"
)
Expand Down Expand Up @@ -112,7 +112,7 @@ func (m *mockedPrivateCaClient) GetCertificateAuthorityCertificate(ctx context.C
}

func buildCertificateConfig(store *mock_store.MockStore) (*Certificate, error) {
config, err := test.GetTestConfigurationPath()
config, err := config.GetTestConfigurationPath()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/users/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/aws/aws-sdk-go-v2/service/kms"
mock_store "github.com/coinbase/baseca/db/mock"
db "github.com/coinbase/baseca/db/sqlc"
"github.com/coinbase/baseca/internal/config"
lib "github.com/coinbase/baseca/internal/lib/authentication"
"github.com/coinbase/baseca/test"
"github.com/stretchr/testify/mock"
)

Expand All @@ -26,7 +26,7 @@ func (m *mockedKmsClient) Verify(ctx context.Context, params *kms.VerifyInput, o
}

func buildUsersConfig(store *mock_store.MockStore) (*User, error) {
config, err := test.GetTestConfigurationPath()
config, err := config.GetTestConfigurationPath()
if err != nil {
return nil, err
}
Expand Down
62 changes: 0 additions & 62 deletions test/config.go

This file was deleted.

0 comments on commit 2ef8f2d

Please sign in to comment.