mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-03 10:08:59 -06:00
tests and docs
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
66
go/libraries/doltcore/dbfactory/aws_test.go
Normal file
66
go/libraries/doltcore/dbfactory/aws_test.go
Normal 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")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
43
go/libraries/doltcore/dbfactory/factory_test.go
Normal file
43
go/libraries/doltcore/dbfactory/factory_test.go
Normal 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)
|
||||
}
|
||||
1
go/libraries/doltcore/dbfactory/testdata/.dolt/config.json
vendored
Executable file
1
go/libraries/doltcore/dbfactory/testdata/.dolt/config.json
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{}
|
||||
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3
vendored
Normal file
Binary file not shown.
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt
vendored
Normal file
Binary file not shown.
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm
vendored
Normal file
Binary file not shown.
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi
vendored
Normal file
Binary file not shown.
0
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/LOCK
vendored
Normal file
0
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/LOCK
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts
vendored
Normal file
Binary file not shown.
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q
vendored
Normal file
Binary file not shown.
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v
vendored
Normal file
Binary file not shown.
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq
vendored
Normal file
Binary file not shown.
1
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest
vendored
Normal file
1
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest
vendored
Normal 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
|
||||
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr
vendored
Normal file
BIN
go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr
vendored
Normal file
Binary file not shown.
8
go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json
vendored
Executable file
8
go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"head": "refs/heads/master",
|
||||
"staged": "1dpev4iss2fv0cbe6261lsfd6kcs24br",
|
||||
"working": "1dpev4iss2fv0cbe6261lsfd6kcs24br",
|
||||
"merge": null,
|
||||
"remotes": null,
|
||||
"branches": null
|
||||
}
|
||||
Reference in New Issue
Block a user