tests and docs

This commit is contained in:
Brian Hendriks
2019-06-10 17:39:34 -07:00
parent d49955d7bd
commit 180dcec349
18 changed files with 135 additions and 5 deletions

View File

@@ -26,10 +26,18 @@ const (
branchParam = "branch"
)
var cloneShortDesc = ""
var cloneLongDesc = ""
var cloneShortDesc = "Clone a data repository into a new directory"
var cloneLongDesc = "Clones a repository into a newly created directory, creates remote-tracking branches for each " +
"branch in the cloned repository (visible using git branch -a), and creates and checks out an initial branch that " +
"is forked from the cloned repository's currently active branch.\n" +
"\n" +
"After the clone, a plain dolt fetch without arguments will update all the remote-tracking branches, and a dolt " +
"pull without arguments will in addition merge the remote branch into the current branch\n" +
"\n" +
"This default configuration is achieved by creating references to the remote branch heads under refs/remotes/origin " +
"and by creating a remote named 'origin'."
var cloneSynopsis = []string{
"[-remote <remote>] [-branch <branch>] <remote-url> <new-dir>",
"[-remote <remote>] [-branch <branch>] [--aws-region <region>] [--aws-creds-type <creds-type>] [--aws-creds-file <file>] [--aws-creds-profile <profile>] <remote-url> <new-dir>",
}
func Clone(commandStr string, args []string, dEnv *env.DoltEnv) int {

View File

@@ -56,7 +56,7 @@ var remoteLongDesc = "With no arguments, shows a list of existing remotes. Sever
var remoteSynopsis = []string{
"[-v | --verbose]",
"add [--aws-region <region>] [--aws-creds-type <creds-type>] [--aws-creds-file <file>] <name> <url>",
"add [--aws-region <region>] [--aws-creds-type <creds-type>] [--aws-creds-file <file>] [--aws-creds-profile <profile>] <name> <url>",
"rename <old> <new>",
"remove <name>",
}
@@ -76,6 +76,7 @@ func Remote(commandStr string, args []string, dEnv *env.DoltEnv) int {
ap := argparser.NewArgParser()
ap.ArgListHelp["region"] = "cloud provider region associated with this remote."
ap.ArgListHelp["creds-type"] = "credential type. Valid options are role, env, and file. See the help section for additional details."
ap.ArgListHelp["profile"] = "AWS profile to use."
ap.SupportsFlag(verboseFlag, "v", "When printing the list of remotes adds additional details.")
ap.SupportsString(dbfactory.AWSRegionParam, "", "region", "")
ap.SupportsValidatedString(dbfactory.AWSCredsTypeParam, "", "creds-type", "", argparser.ValidatorFromStrList(dbfactory.AWSCredsTypeParam, credTypes))

View File

@@ -141,7 +141,9 @@ func validatePath(path string) (string, error) {
pathLen--
}
if strings.Index(path, "/") != -1 {
// Should probably have regex validation of a valid database name here once we decide what valid database names look
// like.
if len(path) == 0 || strings.Index(path, "/") != -1 {
return "", errors.New("invalid database name")
}

View File

@@ -0,0 +1,66 @@
package dbfactory
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestAWSPathValidation(t *testing.T) {
tests := []struct {
name string
path string
expectedPath string
expectErr bool
}{
{
"empty path",
"",
"",
true,
},
{
"basic",
"database",
"database",
false,
},
{
"slash prefix",
"/database",
"database",
false,
},
{
"slash suffix",
"database/",
"database",
false,
},
{
"slash prefix and suffix",
"/database/",
"database",
false,
},
{
"slash in the middle",
"/data/base/",
"",
true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualPath, actualErr := validatePath(test.path)
assert.Equal(t, actualPath, test.expectedPath)
if test.expectErr {
assert.Error(t, actualErr, "Did not expect an error")
} else {
assert.NoError(t, actualErr, "Expected an error")
}
})
}
}

View File

@@ -0,0 +1,43 @@
package dbfactory
import (
"context"
"github.com/attic-labs/noms/go/types"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreateFileDB(t *testing.T) {
ctx := context.Background()
db, err := CreateDB(ctx, "file://testdata/", nil)
assert.NoError(t, err)
datasets := db.Datasets(ctx)
assert.Equal(t, int(datasets.Len()), 2)
master, masterOK := datasets.MaybeGet(ctx, types.String("refs/heads/master"))
assert.True(t, masterOK)
masterVal := master.(types.Ref).TargetValue(ctx, db)
assert.NotNil(t, masterVal)
create, createOK := datasets.MaybeGet(ctx, types.String("refs/internal/create"))
assert.True(t, createOK)
createVal := create.(types.Ref).TargetValue(ctx, db)
assert.NotNil(t, createVal)
_, fakeOK := datasets.MaybeGet(ctx, types.String("refs/heads/fake"))
assert.False(t, fakeOK)
}
func TestCreateMemDB(t *testing.T) {
ctx := context.Background()
db, err := CreateDB(ctx, "mem://", nil)
assert.NoError(t, err)
assert.NotNil(t, db)
}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
4:7.18:eqacm9kvt0cjrrg3pp4epa8bqeo0u582:6l57vgii8u337ahfcpe8r0sku8agdpg7:um7eif38t3jh0i0hutoelu1ded8qbqhr:2:aejlvev89jfts7q5s7ti6koo1gacrsts:1:llm37m4bvu362vnkkbfi7r37d58ijigq:1:e1odhsfrvvklnuh2n5cggo44fmvndr8q:1:i80ob4hj9d797nqvpn2190q52pistj5v:5:5cikgaumcp6n04u1hq2memjmfq7a95fm:1:3qr85kk4r4tobjvh80dujletthct2cr3:2:4bujnjuatdli0klda7ucot0tl836jujt:1:6n6j25hjb3akcri05fkbtaj24mtpcemi:4

View File

@@ -0,0 +1,8 @@
{
"head": "refs/heads/master",
"staged": "1dpev4iss2fv0cbe6261lsfd6kcs24br",
"working": "1dpev4iss2fv0cbe6261lsfd6kcs24br",
"merge": null,
"remotes": null,
"branches": null
}