test logger pkg
This commit is contained in:
parent
196f4013c3
commit
5cb141b6cd
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -286,7 +286,7 @@ jobs:
|
|||||||
-failfast \
|
-failfast \
|
||||||
-p 1 \
|
-p 1 \
|
||||||
-timeout 10m \
|
-timeout 10m \
|
||||||
./pkg/config \
|
./pkg/logger \
|
||||||
2>&1 | tee /tmp/corso-retention-testlog/gotest-ci.log
|
2>&1 | tee /tmp/corso-retention-testlog/gotest-ci.log
|
||||||
|
|
||||||
# run the tests
|
# run the tests
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -96,51 +97,48 @@ func (suite *ConfigSuite) TestReadRepoConfigBasic() {
|
|||||||
token, passphrase, azureClientID, azureSecret,
|
token, passphrase, azureClientID, azureSecret,
|
||||||
disableTLS, disableTLSVerification)
|
disableTLS, disableTLSVerification)
|
||||||
testConfigFilePath := filepath.Join(t.TempDir(), "corso.toml")
|
testConfigFilePath := filepath.Join(t.TempDir(), "corso.toml")
|
||||||
assert.NotEmpty(t, testConfigData)
|
err := os.WriteFile(testConfigFilePath, []byte(testConfigData), 0o700)
|
||||||
assert.NotEmpty(t, testConfigFilePath)
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
_ = vpr
|
|
||||||
// err := os.WriteFile(testConfigFilePath, []byte(testConfigData), 0o700)
|
|
||||||
// require.NoError(t, err, clues.ToCore(err))
|
|
||||||
|
|
||||||
// // Configure viper to read test config file
|
// Configure viper to read test config file
|
||||||
// vpr.SetConfigFile(testConfigFilePath)
|
vpr.SetConfigFile(testConfigFilePath)
|
||||||
|
|
||||||
// // Read and validate config
|
// Read and validate config
|
||||||
// err = vpr.ReadInConfig()
|
err = vpr.ReadInConfig()
|
||||||
// require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
||||||
|
|
||||||
// sc, err := storage.NewStorageConfig(storage.ProviderS3)
|
sc, err := storage.NewStorageConfig(storage.ProviderS3)
|
||||||
// require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
// err = sc.ApplyConfigOverrides(vpr, true, true, nil)
|
err = sc.ApplyConfigOverrides(vpr, true, true, nil)
|
||||||
// require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
// s3Cfg := sc.(*storage.S3Config)
|
s3Cfg := sc.(*storage.S3Config)
|
||||||
|
|
||||||
// assert.Equal(t, b, s3Cfg.Bucket)
|
assert.Equal(t, b, s3Cfg.Bucket)
|
||||||
// assert.Equal(t, "test-prefix/", s3Cfg.Prefix)
|
assert.Equal(t, "test-prefix/", s3Cfg.Prefix)
|
||||||
// assert.Equal(t, disableTLS, strconv.FormatBool(s3Cfg.DoNotUseTLS))
|
assert.Equal(t, disableTLS, strconv.FormatBool(s3Cfg.DoNotUseTLS))
|
||||||
// assert.Equal(t, disableTLSVerification, strconv.FormatBool(s3Cfg.DoNotVerifyTLS))
|
assert.Equal(t, disableTLSVerification, strconv.FormatBool(s3Cfg.DoNotVerifyTLS))
|
||||||
|
|
||||||
// // Config file may or may not be the source of truth for below values. These may be
|
// Config file may or may not be the source of truth for below values. These may be
|
||||||
// // overridden by env vars (and flags but not relevant for this test).
|
// overridden by env vars (and flags but not relevant for this test).
|
||||||
// //
|
//
|
||||||
// // Other alternatives are:
|
// Other alternatives are:
|
||||||
// // 1) unset env vars temporarily so that we can test against config file values. But that
|
// 1) unset env vars temporarily so that we can test against config file values. But that
|
||||||
// // may be problematic if we decide to parallelize tests in future.
|
// may be problematic if we decide to parallelize tests in future.
|
||||||
// // 2) assert against env var values instead of config file values. This can cause issues
|
// 2) assert against env var values instead of config file values. This can cause issues
|
||||||
// // if CI/local env have different config override mechanisms.
|
// if CI/local env have different config override mechanisms.
|
||||||
// // 3) Skip asserts for these keys. They will be validated in other tests. Choosing this
|
// 3) Skip asserts for these keys. They will be validated in other tests. Choosing this
|
||||||
// // option.
|
// option.
|
||||||
|
|
||||||
// // assert.Equal(t, accKey, s3Cfg.AWS.AccessKey)
|
// assert.Equal(t, accKey, s3Cfg.AWS.AccessKey)
|
||||||
// // assert.Equal(t, secret, s3Cfg.AWS.SecretKey)
|
// assert.Equal(t, secret, s3Cfg.AWS.SecretKey)
|
||||||
// // assert.Equal(t, token, s3Cfg.AWS.SessionToken)
|
// assert.Equal(t, token, s3Cfg.AWS.SessionToken)
|
||||||
|
|
||||||
// m365, err := m365ConfigsFromViper(vpr)
|
m365, err := m365ConfigsFromViper(vpr)
|
||||||
// require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
// assert.Equal(t, azureClientID, m365.AzureClientID)
|
assert.Equal(t, azureClientID, m365.AzureClientID)
|
||||||
// assert.Equal(t, azureSecret, m365.AzureClientSecret)
|
assert.Equal(t, azureSecret, m365.AzureClientSecret)
|
||||||
// assert.Equal(t, tID, m365.AzureTenantID)
|
assert.Equal(t, tID, m365.AzureTenantID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfigSuite) TestWriteReadConfig() {
|
func (suite *ConfigSuite) TestWriteReadConfig() {
|
||||||
@ -177,33 +175,29 @@ func (suite *ConfigSuite) TestWriteReadConfig() {
|
|||||||
Host: host,
|
Host: host,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NotEmpty(t, s3Cfg)
|
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, rOpts, repoID)
|
||||||
assert.NotEmpty(t, m365)
|
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
||||||
assert.NotEmpty(t, rOpts)
|
|
||||||
|
|
||||||
// err = writeRepoConfigWithViper(vpr, s3Cfg, m365, rOpts, repoID)
|
err = vpr.ReadInConfig()
|
||||||
// require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
||||||
|
|
||||||
// err = vpr.ReadInConfig()
|
sc, err := storage.NewStorageConfig(storage.ProviderS3)
|
||||||
// require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
err = sc.ApplyConfigOverrides(vpr, true, true, nil)
|
||||||
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
// sc, err := storage.NewStorageConfig(storage.ProviderS3)
|
readS3Cfg := sc.(*storage.S3Config)
|
||||||
// require.NoError(t, err, clues.ToCore(err))
|
assert.Equal(t, readS3Cfg.Bucket, s3Cfg.Bucket)
|
||||||
// err = sc.ApplyConfigOverrides(vpr, true, true, nil)
|
assert.Equal(t, readS3Cfg.DoNotUseTLS, s3Cfg.DoNotUseTLS)
|
||||||
// require.NoError(t, err, clues.ToCore(err))
|
assert.Equal(t, readS3Cfg.DoNotVerifyTLS, s3Cfg.DoNotVerifyTLS)
|
||||||
|
|
||||||
// readS3Cfg := sc.(*storage.S3Config)
|
readM365, err := m365ConfigsFromViper(vpr)
|
||||||
// assert.Equal(t, readS3Cfg.Bucket, s3Cfg.Bucket)
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
// assert.Equal(t, readS3Cfg.DoNotUseTLS, s3Cfg.DoNotUseTLS)
|
assert.Equal(t, readM365.AzureTenantID, m365.AzureTenantID)
|
||||||
// assert.Equal(t, readS3Cfg.DoNotVerifyTLS, s3Cfg.DoNotVerifyTLS)
|
|
||||||
|
|
||||||
// readM365, err := m365ConfigsFromViper(vpr)
|
gotUser, gotHost := getUserHost(vpr, true)
|
||||||
// require.NoError(t, err, clues.ToCore(err))
|
assert.Equal(t, user, gotUser)
|
||||||
// assert.Equal(t, readM365.AzureTenantID, m365.AzureTenantID)
|
assert.Equal(t, host, gotHost)
|
||||||
|
|
||||||
// gotUser, gotHost := getUserHost(vpr, true)
|
|
||||||
// assert.Equal(t, user, gotUser)
|
|
||||||
// assert.Equal(t, host, gotHost)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfigSuite) TestMustMatchConfig() {
|
func (suite *ConfigSuite) TestMustMatchConfig() {
|
||||||
@ -230,70 +224,65 @@ func (suite *ConfigSuite) TestMustMatchConfig() {
|
|||||||
|
|
||||||
m365PathKeys := []string{}
|
m365PathKeys := []string{}
|
||||||
|
|
||||||
assert.NotEmpty(t, s3Cfg)
|
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, repository.Options{}, "repoid")
|
||||||
assert.NotEmpty(t, m365)
|
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
||||||
|
|
||||||
_ = m365PathKeys
|
err = vpr.ReadInConfig()
|
||||||
|
require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
||||||
|
|
||||||
// err = writeRepoConfigWithViper(vpr, s3Cfg, m365, repository.Options{}, "repoid")
|
table := []struct {
|
||||||
// require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
name string
|
||||||
|
input map[string]string
|
||||||
// err = vpr.ReadInConfig()
|
errCheck assert.ErrorAssertionFunc
|
||||||
// require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
}{
|
||||||
|
{
|
||||||
// table := []struct {
|
name: "full match",
|
||||||
// name string
|
input: map[string]string{
|
||||||
// input map[string]string
|
storage.Bucket: bkt,
|
||||||
// errCheck assert.ErrorAssertionFunc
|
account.AzureTenantID: tid,
|
||||||
// }{
|
},
|
||||||
// {
|
errCheck: assert.NoError,
|
||||||
// name: "full match",
|
},
|
||||||
// input: map[string]string{
|
{
|
||||||
// storage.Bucket: bkt,
|
name: "empty values",
|
||||||
// account.AzureTenantID: tid,
|
input: map[string]string{
|
||||||
// },
|
storage.Bucket: "",
|
||||||
// errCheck: assert.NoError,
|
account.AzureTenantID: "",
|
||||||
// },
|
},
|
||||||
// {
|
errCheck: assert.NoError,
|
||||||
// name: "empty values",
|
},
|
||||||
// input: map[string]string{
|
{
|
||||||
// storage.Bucket: "",
|
name: "no overrides",
|
||||||
// account.AzureTenantID: "",
|
input: map[string]string{},
|
||||||
// },
|
errCheck: assert.NoError,
|
||||||
// errCheck: assert.NoError,
|
},
|
||||||
// },
|
{
|
||||||
// {
|
name: "nil map",
|
||||||
// name: "no overrides",
|
input: nil,
|
||||||
// input: map[string]string{},
|
errCheck: assert.NoError,
|
||||||
// errCheck: assert.NoError,
|
},
|
||||||
// },
|
{
|
||||||
// {
|
name: "no recognized keys",
|
||||||
// name: "nil map",
|
input: map[string]string{
|
||||||
// input: nil,
|
"fnords": "smurfs",
|
||||||
// errCheck: assert.NoError,
|
"nonsense": "",
|
||||||
// },
|
},
|
||||||
// {
|
errCheck: assert.NoError,
|
||||||
// name: "no recognized keys",
|
},
|
||||||
// input: map[string]string{
|
{
|
||||||
// "fnords": "smurfs",
|
name: "mismatch",
|
||||||
// "nonsense": "",
|
input: map[string]string{
|
||||||
// },
|
storage.Bucket: tid,
|
||||||
// errCheck: assert.NoError,
|
account.AzureTenantID: bkt,
|
||||||
// },
|
},
|
||||||
// {
|
errCheck: assert.Error,
|
||||||
// name: "mismatch",
|
},
|
||||||
// input: map[string]string{
|
}
|
||||||
// storage.Bucket: tid,
|
for _, test := range table {
|
||||||
// account.AzureTenantID: bkt,
|
suite.Run(test.name, func() {
|
||||||
// },
|
test.errCheck(suite.T(), mustMatchConfig(vpr, test.input, m365PathKeys), clues.ToCore(err))
|
||||||
// errCheck: assert.Error,
|
})
|
||||||
// },
|
}
|
||||||
// }
|
|
||||||
// for _, test := range table {
|
|
||||||
// suite.Run(test.name, func() {
|
|
||||||
// test.errCheck(suite.T(), mustMatchConfig(vpr, test.input, m365PathKeys), clues.ToCore(err))
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfigSuite) TestReadFromFlags() {
|
func (suite *ConfigSuite) TestReadFromFlags() {
|
||||||
@ -447,43 +436,41 @@ func (suite *ConfigIntegrationSuite) TestGetStorageAndAccount() {
|
|||||||
}
|
}
|
||||||
m365 := account.M365Config{AzureTenantID: tid}
|
m365 := account.M365Config{AzureTenantID: tid}
|
||||||
|
|
||||||
assert.NotEmpty(t, s3Cfg)
|
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, repository.Options{}, "repoid")
|
||||||
assert.NotEmpty(t, m365)
|
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
||||||
// err = writeRepoConfigWithViper(vpr, s3Cfg, m365, repository.Options{}, "repoid")
|
|
||||||
// require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
|
||||||
|
|
||||||
// require.Equal(
|
require.Equal(
|
||||||
// t,
|
t,
|
||||||
// account.ProviderM365.String(),
|
account.ProviderM365.String(),
|
||||||
// vpr.GetString(account.AccountProviderTypeKey),
|
vpr.GetString(account.AccountProviderTypeKey),
|
||||||
// "viper should have m365 as the account provider")
|
"viper should have m365 as the account provider")
|
||||||
|
|
||||||
// err = vpr.ReadInConfig()
|
err = vpr.ReadInConfig()
|
||||||
// require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
require.NoError(t, err, "reading repo config", clues.ToCore(err))
|
||||||
|
|
||||||
// cfg, err := getStorageAndAccountWithViper(ctx, vpr, storage.ProviderS3, true, true, nil)
|
cfg, err := getStorageAndAccountWithViper(ctx, vpr, storage.ProviderS3, true, true, nil)
|
||||||
// require.NoError(t, err, "getting storage and account from config", clues.ToCore(err))
|
require.NoError(t, err, "getting storage and account from config", clues.ToCore(err))
|
||||||
|
|
||||||
// readS3Cfg, err := cfg.Storage.ToS3Config()
|
readS3Cfg, err := cfg.Storage.ToS3Config()
|
||||||
// require.NoError(t, err, "reading s3 config from storage", clues.ToCore(err))
|
require.NoError(t, err, "reading s3 config from storage", clues.ToCore(err))
|
||||||
|
|
||||||
// assert.Equal(t, readS3Cfg.Bucket, s3Cfg.Bucket)
|
assert.Equal(t, readS3Cfg.Bucket, s3Cfg.Bucket)
|
||||||
// assert.Equal(t, readS3Cfg.Endpoint, s3Cfg.Endpoint)
|
assert.Equal(t, readS3Cfg.Endpoint, s3Cfg.Endpoint)
|
||||||
// assert.Equal(t, readS3Cfg.Prefix, s3Cfg.Prefix)
|
assert.Equal(t, readS3Cfg.Prefix, s3Cfg.Prefix)
|
||||||
// assert.Equal(t, readS3Cfg.DoNotUseTLS, s3Cfg.DoNotUseTLS)
|
assert.Equal(t, readS3Cfg.DoNotUseTLS, s3Cfg.DoNotUseTLS)
|
||||||
// assert.Equal(t, readS3Cfg.DoNotVerifyTLS, s3Cfg.DoNotVerifyTLS)
|
assert.Equal(t, readS3Cfg.DoNotVerifyTLS, s3Cfg.DoNotVerifyTLS)
|
||||||
// assert.Equal(t, cfg.RepoID, "repoid")
|
assert.Equal(t, cfg.RepoID, "repoid")
|
||||||
|
|
||||||
// common, err := cfg.Storage.CommonConfig()
|
common, err := cfg.Storage.CommonConfig()
|
||||||
// require.NoError(t, err, "reading common config from storage", clues.ToCore(err))
|
require.NoError(t, err, "reading common config from storage", clues.ToCore(err))
|
||||||
// assert.Equal(t, common.CorsoPassphrase, os.Getenv(credentials.CorsoPassphrase))
|
assert.Equal(t, common.CorsoPassphrase, os.Getenv(credentials.CorsoPassphrase))
|
||||||
|
|
||||||
// readM365, err := cfg.Account.M365Config()
|
readM365, err := cfg.Account.M365Config()
|
||||||
// require.NoError(t, err, "reading m365 config from account", clues.ToCore(err))
|
require.NoError(t, err, "reading m365 config from account", clues.ToCore(err))
|
||||||
// // Env var gets preference here. Where to get env tenantID from
|
// Env var gets preference here. Where to get env tenantID from
|
||||||
// // assert.Equal(t, readM365.AzureTenantID, m365.AzureTenantID)
|
// assert.Equal(t, readM365.AzureTenantID, m365.AzureTenantID)
|
||||||
// assert.Equal(t, readM365.AzureClientID, os.Getenv(credentials.AzureClientID))
|
assert.Equal(t, readM365.AzureClientID, os.Getenv(credentials.AzureClientID))
|
||||||
// assert.Equal(t, readM365.AzureClientSecret, os.Getenv(credentials.AzureClientSecret))
|
assert.Equal(t, readM365.AzureClientSecret, os.Getenv(credentials.AzureClientSecret))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfigIntegrationSuite) TestGetStorageAndAccount_noFileOnlyOverrides() {
|
func (suite *ConfigIntegrationSuite) TestGetStorageAndAccount_noFileOnlyOverrides() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user