From 180dcec3490b7359dee7b103f0f6226c3da0c5d6 Mon Sep 17 00:00:00 2001 From: Brian Hendriks Date: Mon, 10 Jun 2019 17:39:34 -0700 Subject: [PATCH] tests and docs --- go/cmd/dolt/commands/clone.go | 14 +++- go/cmd/dolt/commands/remote.go | 3 +- go/libraries/doltcore/dbfactory/aws.go | 4 +- go/libraries/doltcore/dbfactory/aws_test.go | 66 ++++++++++++++++++ .../doltcore/dbfactory/factory_test.go | 43 ++++++++++++ .../dbfactory/testdata/.dolt/config.json | 1 + .../noms/3qr85kk4r4tobjvh80dujletthct2cr3 | Bin 0 -> 305 bytes .../noms/4bujnjuatdli0klda7ucot0tl836jujt | Bin 0 -> 57 bytes .../noms/5cikgaumcp6n04u1hq2memjmfq7a95fm | Bin 0 -> 122 bytes .../noms/6n6j25hjb3akcri05fkbtaj24mtpcemi | Bin 0 -> 309 bytes .../dbfactory/testdata/.dolt/noms/LOCK | 0 .../noms/aejlvev89jfts7q5s7ti6koo1gacrsts | Bin 0 -> 211 bytes .../noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q | Bin 0 -> 211 bytes .../noms/i80ob4hj9d797nqvpn2190q52pistj5v | Bin 0 -> 1402 bytes .../noms/llm37m4bvu362vnkkbfi7r37d58ijigq | Bin 0 -> 211 bytes .../dbfactory/testdata/.dolt/noms/manifest | 1 + .../noms/um7eif38t3jh0i0hutoelu1ded8qbqhr | Bin 0 -> 574 bytes .../dbfactory/testdata/.dolt/repo_state.json | 8 +++ 18 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 go/libraries/doltcore/dbfactory/aws_test.go create mode 100644 go/libraries/doltcore/dbfactory/factory_test.go create mode 100755 go/libraries/doltcore/dbfactory/testdata/.dolt/config.json create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3 create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/LOCK create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest create mode 100644 go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr create mode 100755 go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json diff --git a/go/cmd/dolt/commands/clone.go b/go/cmd/dolt/commands/clone.go index 112ba2a579..c5e39deaca 100644 --- a/go/cmd/dolt/commands/clone.go +++ b/go/cmd/dolt/commands/clone.go @@ -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 ] [-branch ] ", + "[-remote ] [-branch ] [--aws-region ] [--aws-creds-type ] [--aws-creds-file ] [--aws-creds-profile ] ", } func Clone(commandStr string, args []string, dEnv *env.DoltEnv) int { diff --git a/go/cmd/dolt/commands/remote.go b/go/cmd/dolt/commands/remote.go index aad1664165..297e69346c 100644 --- a/go/cmd/dolt/commands/remote.go +++ b/go/cmd/dolt/commands/remote.go @@ -56,7 +56,7 @@ var remoteLongDesc = "With no arguments, shows a list of existing remotes. Sever var remoteSynopsis = []string{ "[-v | --verbose]", - "add [--aws-region ] [--aws-creds-type ] [--aws-creds-file ] ", + "add [--aws-region ] [--aws-creds-type ] [--aws-creds-file ] [--aws-creds-profile ] ", "rename ", "remove ", } @@ -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)) diff --git a/go/libraries/doltcore/dbfactory/aws.go b/go/libraries/doltcore/dbfactory/aws.go index 30ba6431d2..38d51535b7 100644 --- a/go/libraries/doltcore/dbfactory/aws.go +++ b/go/libraries/doltcore/dbfactory/aws.go @@ -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") } diff --git a/go/libraries/doltcore/dbfactory/aws_test.go b/go/libraries/doltcore/dbfactory/aws_test.go new file mode 100644 index 0000000000..0f6ac64568 --- /dev/null +++ b/go/libraries/doltcore/dbfactory/aws_test.go @@ -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") + } + }) + } +} diff --git a/go/libraries/doltcore/dbfactory/factory_test.go b/go/libraries/doltcore/dbfactory/factory_test.go new file mode 100644 index 0000000000..12aebee84f --- /dev/null +++ b/go/libraries/doltcore/dbfactory/factory_test.go @@ -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) +} diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/config.json b/go/libraries/doltcore/dbfactory/testdata/.dolt/config.json new file mode 100755 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/go/libraries/doltcore/dbfactory/testdata/.dolt/config.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3 b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3 new file mode 100644 index 0000000000000000000000000000000000000000..fe640c579f605bc5477d9f57ccf44a172da96874 GIT binary patch literal 305 zcmZ3*Xv4|ooS&PUS;EYcn_7~{$-&5WBPFpUk(DJSwK$nc!Uf1yC`v8JFU~Bu2Vbq!#5R=IBFQ#J+F#9=`>4 z2UaHQeY(5C{JaE%c)T$SBTul?{%qChz&kRl+s^?&P)Ln_Jd0sxn*XK?@k literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt new file mode 100644 index 0000000000000000000000000000000000000000..c41b419f7c20cf86bd1a0030dd7abbbd06e7ef12 GIT binary patch literal 57 zcmZSPU}Ip=+7fK=!u{H&Tf*+M7$AT%eP#FypGmJ@6s*v61`07k#hL$ay>Un-`CR}2 D-mnpz literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm new file mode 100644 index 0000000000000000000000000000000000000000..3b5b7a20b7e48b784d8141fd7551e01aeb4ff60f GIT binary patch literal 122 zcma#r!N$PEBv_Q1R;-_qnwV0opPN`*l3K*RZ}uL)1$GBkChL8=yTbgu1cP|IF$*J; z2&z>% literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi new file mode 100644 index 0000000000000000000000000000000000000000..129a66afb172e77c242e553effefb30b830d4013 GIT binary patch literal 309 zcmZQ#VPKrS)j!_y0VkVter|4N2{TJ>YDpp|0|R?OVo_>dNihcl18Z4gPH8H8LvT)F z!QD2sI~-CUJuc5X^f#81hk;S={;j(%ADr137@0J5_0w`ni!=0%5|dLbO_MBAjV#Oz zQZ3Dr(hQPJEmO=*6OD~bOidEmHTfqL*%``BUuS*IV%Pr!cfDQhoh(dS%A9XYCUEkk z!|$vXvwz<)jv~F)$qa7$^1nOY{ QVi1_|f9s7yD#`Bx0I^kQYybcN literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/LOCK b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts new file mode 100644 index 0000000000000000000000000000000000000000..2e72188895eb28914b5c9549b831922f596d17b7 GIT binary patch literal 211 zcmbQu_+b_s12dC`u6|lhX>o?WVX8rLN~)!qk)^Svfu(_wQCf0Rs)3oMWvW@Sr9rX< zyC(mHB0EF5>FcboS?v0s;I6l;y_1EBNw6q2tyn)JH8G`FKR2Un-`CR}2$J|R; literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q new file mode 100644 index 0000000000000000000000000000000000000000..6d8ed134640afa0b85e811353c45ab4c0f816a80 GIT binary patch literal 211 zcmbQu_+b_s12dC`u6|lhX>o>rqPe+wilv3IrJ0erajK!AajIFGS*m4nijk4Ik+F$6 zyC(mHB0EF5>FcboS?v0s;I6l;y_1EBNw6q2tyn)JH8G`FKR2Un-`CR}2N(f1! literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v new file mode 100644 index 0000000000000000000000000000000000000000..8e211ed117e53e35836b68a4a27ba2ea16104eba GIT binary patch literal 1402 zcmb7?du$X%9LIOJGk3e~9la~p>-C{oXcK$N_3jF_2)5X?28vv*lt9!b%iQi=^YvdDWYGE+8 zpv!hxT5U&;ZJFLFFgmJi^?{qyrVSh9XWo!tL%pXP6GDfqI}wSr$%oI@DOEM=)3$-t zPFnt>ykif5Rh|VscCIxk$UhI4!x~lDz>i=`ark<9$Ak-3gxnjkld(y78k~M1a*J=H z>GYZYLHVBXIJ_p{-GnJq8>_eP@g z%Z+whT(|+2@-Lch6P^~=%J>dZ@t4>7D}Yp5Sv%9Iv7s!MWMVUo<%?abSo}c#Ju;O55@#!s9^{z6H zB>BpGVlgd%Y7S1hw=JEh`s&@}`Ju6`=kNX+EsjM$i~O^Rc^>j={wCsbz5-o=D*vBQ z@&752P$iys)iPL6^@kwI#M=LK78v~`PdWFYq<`wo?WsrpLb4zn?u52@8x0tg$Vt}|2Lq& z#eWHG`+tLR#+HYVjqDa@##};?R3C|^tQ<{8o0m1=W`vSWXqj~>0jD*7<>=EZ-(P;@;^x&2NABANB+1Wnq|r1+290JAW!P~~?mpV}NbB*( z^oAckJ=FY8NT|@30#OPScJfie4nbB_cQE(&FPq21i(Z=Yrt9#Fww}_av{6czw+4!2D^PKXCJdi<8($)w%DQDqrz$>G3IV cMvRt`N^|NCejf75zs_EK{(}>B`uE+x10bihb^rhX literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq new file mode 100644 index 0000000000000000000000000000000000000000..95ba0a3fd78a631ada25a355044d8dba4942f24d GIT binary patch literal 211 zcmbQu_+b_s12dC`u6|lhX>o?WxtXO|nx&bgQL1sGNs57qvAI!FiiMGpak7bVvSo@9 zyC(mHB0EF5>FcboS?v0s;I6l;y_1EBNw6q2tyn)JH8G`FKR20|YFd fAltsJ`Tyt2a%tscpb#TeeD?pXHx8*JzY72WZJkN& literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest new file mode 100644 index 0000000000..c57721e5d7 --- /dev/null +++ b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest @@ -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 \ No newline at end of file diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr new file mode 100644 index 0000000000000000000000000000000000000000..8906c6895222d1473688d67d34d760a774306d58 GIT binary patch literal 574 zcmZuuO=uHA6rP#v>}KMIW<%4a7qR#UqMODN3Sx`UXlV~o6cjado$OA`(A}MMXHqR5 zRD^;DMI@Le9f_wjx2``*vgL1K=JDB>z* zL`+eVhGsROiee*R(nlGosAAi2zRDuXLzHhMoW_SjKHK52-*$bm1y;UI&ap&t5u;Su z9Wr7XF@zf}7IUI_#56_J&V6{fvh;AD)usuHl}rO@JzacKTONCU&v!RI-W_>U1pVGH z*?${2ZV}JXu*1lKWk9;_6@V`ds9vNi2Ow;xZ9wcmgvtvVULu5orlO6INz(>495evT z1}Ap`8$e|4%+{r~u-iU+u~uu2z3998?$xuxod;j12*x#qj6__J8R@sQJ1=2P%goza zC7-iM<^=AmS9KE5@@Mcg?sea^F=IGLbg;`-~;XC9jXAxB>$OD#qN zS&FDsEV0h5FSRO@-`Cb>w|-{Zf23_-Zmzwn(*SZ@8^OL1_XcLD{{d)9vb%+1u*l*Q4vMc}q literal 0 HcmV?d00001 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json b/go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json new file mode 100755 index 0000000000..54f95d34ff --- /dev/null +++ b/go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json @@ -0,0 +1,8 @@ +{ + "head": "refs/heads/master", + "staged": "1dpev4iss2fv0cbe6261lsfd6kcs24br", + "working": "1dpev4iss2fv0cbe6261lsfd6kcs24br", + "merge": null, + "remotes": null, + "branches": null +} \ No newline at end of file