github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/cmd/noms/noms_ds_test.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // This file incorporates work covered by the following copyright and 16 // permission notice: 17 // 18 // Copyright 2016 Attic Labs, Inc. All rights reserved. 19 // Licensed under the Apache License, version 2.0: 20 // http://www.apache.org/licenses/LICENSE-2.0 21 22 package main 23 24 import ( 25 "context" 26 "testing" 27 28 "github.com/stretchr/testify/suite" 29 30 "github.com/dolthub/dolt/go/store/datas" 31 "github.com/dolthub/dolt/go/store/nbs" 32 "github.com/dolthub/dolt/go/store/spec" 33 "github.com/dolthub/dolt/go/store/types" 34 "github.com/dolthub/dolt/go/store/util/clienttest" 35 ) 36 37 func TestDs(t *testing.T) { 38 suite.Run(t, &nomsDsTestSuite{}) 39 } 40 41 type nomsDsTestSuite struct { 42 clienttest.ClientTestSuite 43 } 44 45 func (s *nomsDsTestSuite) TestEmptyNomsDs() { 46 dir := s.DBDir 47 48 cs, err := nbs.NewLocalStore(context.Background(), types.Format_Default.VersionString(), dir, clienttest.DefaultMemTableSize) 49 s.NoError(err) 50 ds := datas.NewDatabase(cs) 51 52 ds.Close() 53 54 dbSpec := spec.CreateDatabaseSpecString("nbs", dir) 55 rtnVal, _ := s.MustRun(main, []string{"ds", dbSpec}) 56 s.Equal("", rtnVal) 57 } 58 59 func (s *nomsDsTestSuite) TestNomsDs() { 60 dir := s.DBDir 61 62 cs, err := nbs.NewLocalStore(context.Background(), types.Format_Default.VersionString(), dir, clienttest.DefaultMemTableSize) 63 s.NoError(err) 64 db := datas.NewDatabase(cs) 65 66 id := "testdataset" 67 set, err := db.GetDataset(context.Background(), id) 68 s.NoError(err) 69 set, err = db.CommitValue(context.Background(), set, types.String("Commit Value")) 70 s.NoError(err) 71 72 id2 := "testdataset2" 73 set2, err := db.GetDataset(context.Background(), id2) 74 s.NoError(err) 75 set2, err = db.CommitValue(context.Background(), set2, types.String("Commit Value2")) 76 s.NoError(err) 77 78 err = db.Close() 79 s.NoError(err) 80 81 dbSpec := spec.CreateDatabaseSpecString("nbs", dir) 82 datasetName := spec.CreateValueSpecString("nbs", dir, id) 83 dataset2Name := spec.CreateValueSpecString("nbs", dir, id2) 84 85 // both datasets show up 86 rtnVal, _ := s.MustRun(main, []string{"ds", dbSpec}) 87 s.Equal(id+"\n"+id2+"\n", rtnVal) 88 89 // both datasets again, to make sure printing doesn't change them 90 rtnVal, _ = s.MustRun(main, []string{"ds", dbSpec}) 91 s.Equal(id+"\n"+id2+"\n", rtnVal) 92 93 // delete one dataset, print message at delete 94 rtnVal, _ = s.MustRun(main, []string{"ds", "-d", datasetName}) 95 s.Equal("Deleted "+datasetName+" (was #7jrps2q0ubq0phnha37gd6051m8uqq6b)\n", rtnVal) 96 97 // print datasets, just one left 98 rtnVal, _ = s.MustRun(main, []string{"ds", dbSpec}) 99 s.Equal(id2+"\n", rtnVal) 100 101 // delete the second dataset 102 rtnVal, _ = s.MustRun(main, []string{"ds", "-d", dataset2Name}) 103 s.Equal("Deleted "+dataset2Name+" (was #hiqpb7kk36vo80uc36virlnrddru2o7h)\n", rtnVal) 104 105 // print datasets, none left 106 rtnVal, _ = s.MustRun(main, []string{"ds", dbSpec}) 107 s.Equal("", rtnVal) 108 }