<!-- PR description--> New commands to initialize & connect to a repo on local or network attached storage. * `repo init filesystem --path /tmp/repo` * `repo connect filesystem --path /tmp/repo` Includes basic unit & e2e tests. More coverage to be added in a following PR to keep the size contained. **Updates:** * Added Repo path sanitization i.e. handle relative paths, make paths cross platform compatible, etc. * Removed retention artifacts, not supported for filesystem storage. * cli docs - auto updated. * Manually tested with all corso backup/restore/export commands. **Doesn't include** 1. Symlinks 2. User ids wiring into repo. 3. Repos documentation update - in an upcoming PR. 4. Prefix support -> kopia doesn't support prefixes for `filesystem` storage 5. More E2E tests. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [x] 🕐 Yes, but in a later PR - [ ] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #1416 #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
156 lines
4.2 KiB
Go
156 lines
4.2 KiB
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/alcionai/clues"
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/alcionai/corso/src/cli/flags"
|
|
"github.com/alcionai/corso/src/internal/tester"
|
|
)
|
|
|
|
type FlagUnitSuite struct {
|
|
tester.Suite
|
|
}
|
|
|
|
func TestFlagUnitSuite(t *testing.T) {
|
|
suite.Run(t, &FlagUnitSuite{Suite: tester.NewUnitSuite(t)})
|
|
}
|
|
|
|
func (suite *FlagUnitSuite) TestAddAzureCredsFlags() {
|
|
t := suite.T()
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "test",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
assert.Equal(t, "tenantID", flags.AzureClientTenantFV, flags.AzureClientTenantFN)
|
|
assert.Equal(t, "clientID", flags.AzureClientIDFV, flags.AzureClientIDFN)
|
|
assert.Equal(t, "secret", flags.AzureClientSecretFV, flags.AzureClientSecretFN)
|
|
},
|
|
}
|
|
|
|
flags.AddAzureCredsFlags(cmd)
|
|
// Test arg parsing for few args
|
|
cmd.SetArgs([]string{
|
|
"test",
|
|
"--" + flags.AzureClientIDFN, "clientID",
|
|
"--" + flags.AzureClientTenantFN, "tenantID",
|
|
"--" + flags.AzureClientSecretFN, "secret",
|
|
})
|
|
|
|
err := cmd.Execute()
|
|
require.NoError(t, err, clues.ToCore(err))
|
|
}
|
|
|
|
func (suite *FlagUnitSuite) TestAddAWSCredsFlags() {
|
|
t := suite.T()
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "test",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
assert.Equal(t, "accesskey", flags.AWSAccessKeyFV, flags.AWSAccessKeyFN)
|
|
assert.Equal(t, "secretkey", flags.AWSSecretAccessKeyFV, flags.AWSSecretAccessKeyFN)
|
|
assert.Equal(t, "token", flags.AWSSessionTokenFV, flags.AWSSessionTokenFN)
|
|
},
|
|
}
|
|
|
|
flags.AddAWSCredsFlags(cmd)
|
|
// Test arg parsing for few args
|
|
cmd.SetArgs([]string{
|
|
"test",
|
|
"--" + flags.AWSAccessKeyFN, "accesskey",
|
|
"--" + flags.AWSSecretAccessKeyFN, "secretkey",
|
|
"--" + flags.AWSSessionTokenFN, "token",
|
|
})
|
|
|
|
err := cmd.Execute()
|
|
require.NoError(t, err, clues.ToCore(err))
|
|
}
|
|
|
|
func (suite *FlagUnitSuite) TestAddCorsoPassphraseFlags() {
|
|
t := suite.T()
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "test",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
assert.Equal(t, "passphrase", flags.CorsoPassphraseFV, flags.CorsoPassphraseFN)
|
|
},
|
|
}
|
|
|
|
flags.AddCorsoPassphaseFlags(cmd)
|
|
// Test arg parsing for few args
|
|
cmd.SetArgs([]string{
|
|
"test",
|
|
"--" + flags.CorsoPassphraseFN, "passphrase",
|
|
})
|
|
|
|
err := cmd.Execute()
|
|
require.NoError(t, err, clues.ToCore(err))
|
|
}
|
|
|
|
func (suite *FlagUnitSuite) TestAddS3BucketFlags() {
|
|
t := suite.T()
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "test",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
assert.Equal(t, "bucket1", flags.BucketFV, flags.BucketFN)
|
|
assert.Equal(t, "endpoint1", flags.EndpointFV, flags.EndpointFN)
|
|
assert.Equal(t, "prefix1", flags.PrefixFV, flags.PrefixFN)
|
|
assert.True(t, flags.DoNotUseTLSFV, flags.DoNotUseTLSFN)
|
|
assert.True(t, flags.DoNotVerifyTLSFV, flags.DoNotVerifyTLSFN)
|
|
assert.True(t, flags.SucceedIfExistsFV, flags.SucceedIfExistsFN)
|
|
},
|
|
}
|
|
|
|
flags.AddS3BucketFlags(cmd)
|
|
// Test arg parsing for few args
|
|
cmd.SetArgs([]string{
|
|
"test",
|
|
"--" + flags.BucketFN, "bucket1",
|
|
"--" + flags.EndpointFN, "endpoint1",
|
|
"--" + flags.PrefixFN, "prefix1",
|
|
"--" + flags.DoNotUseTLSFN,
|
|
"--" + flags.DoNotVerifyTLSFN,
|
|
"--" + flags.SucceedIfExistsFN,
|
|
})
|
|
|
|
err := cmd.Execute()
|
|
require.NoError(t, err, clues.ToCore(err))
|
|
}
|
|
|
|
func (suite *FlagUnitSuite) TestFilesystemFlags() {
|
|
t := suite.T()
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "test",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
assert.Equal(t, "/tmp/test", flags.FilesystemPathFV, flags.FilesystemPathFN)
|
|
assert.True(t, flags.SucceedIfExistsFV, flags.SucceedIfExistsFN)
|
|
assert.Equal(t, "tenantID", flags.AzureClientTenantFV, flags.AzureClientTenantFN)
|
|
assert.Equal(t, "clientID", flags.AzureClientIDFV, flags.AzureClientIDFN)
|
|
assert.Equal(t, "secret", flags.AzureClientSecretFV, flags.AzureClientSecretFN)
|
|
assert.Equal(t, "passphrase", flags.CorsoPassphraseFV, flags.CorsoPassphraseFN)
|
|
},
|
|
}
|
|
|
|
flags.AddFilesystemFlags(cmd)
|
|
|
|
cmd.SetArgs([]string{
|
|
"test",
|
|
"--" + flags.FilesystemPathFN, "/tmp/test",
|
|
"--" + flags.SucceedIfExistsFN,
|
|
"--" + flags.AzureClientIDFN, "clientID",
|
|
"--" + flags.AzureClientTenantFN, "tenantID",
|
|
"--" + flags.AzureClientSecretFN, "secret",
|
|
"--" + flags.CorsoPassphraseFN, "passphrase",
|
|
})
|
|
|
|
err := cmd.Execute()
|
|
require.NoError(t, err, clues.ToCore(err))
|
|
}
|