github.com/jbendotnet/noms@v0.0.0-20190904222105-c43e4293ea92/cmd/noms/noms_ds_test.go (about) 1 // Copyright 2016 Attic Labs, Inc. All rights reserved. 2 // Licensed under the Apache License, version 2.0: 3 // http://www.apache.org/licenses/LICENSE-2.0 4 5 package main 6 7 import ( 8 "testing" 9 10 "github.com/attic-labs/noms/go/datas" 11 "github.com/attic-labs/noms/go/nbs" 12 "github.com/attic-labs/noms/go/spec" 13 "github.com/attic-labs/noms/go/types" 14 "github.com/attic-labs/noms/go/util/clienttest" 15 "github.com/stretchr/testify/suite" 16 ) 17 18 func TestDs(t *testing.T) { 19 suite.Run(t, &nomsDsTestSuite{}) 20 } 21 22 type nomsDsTestSuite struct { 23 clienttest.ClientTestSuite 24 } 25 26 func (s *nomsDsTestSuite) TestEmptyNomsDs() { 27 dir := s.DBDir 28 29 cs := nbs.NewLocalStore(dir, clienttest.DefaultMemTableSize) 30 ds := datas.NewDatabase(cs) 31 32 ds.Close() 33 34 dbSpec := spec.CreateDatabaseSpecString("nbs", dir) 35 rtnVal, _ := s.MustRun(main, []string{"ds", dbSpec}) 36 s.Equal("", rtnVal) 37 } 38 39 func (s *nomsDsTestSuite) TestNomsDs() { 40 dir := s.DBDir 41 42 cs := nbs.NewLocalStore(dir, clienttest.DefaultMemTableSize) 43 db := datas.NewDatabase(cs) 44 45 id := "testdataset" 46 set := db.GetDataset(id) 47 set, err := db.CommitValue(set, types.String("Commit Value")) 48 s.NoError(err) 49 50 id2 := "testdataset2" 51 set2 := db.GetDataset(id2) 52 set2, err = db.CommitValue(set2, types.String("Commit Value2")) 53 s.NoError(err) 54 55 err = db.Close() 56 s.NoError(err) 57 58 dbSpec := spec.CreateDatabaseSpecString("nbs", dir) 59 datasetName := spec.CreateValueSpecString("nbs", dir, id) 60 dataset2Name := spec.CreateValueSpecString("nbs", dir, id2) 61 62 // both datasets show up 63 rtnVal, _ := s.MustRun(main, []string{"ds", dbSpec}) 64 s.Equal(id+"\n"+id2+"\n", rtnVal) 65 66 // both datasets again, to make sure printing doesn't change them 67 rtnVal, _ = s.MustRun(main, []string{"ds", dbSpec}) 68 s.Equal(id+"\n"+id2+"\n", rtnVal) 69 70 // delete one dataset, print message at delete 71 rtnVal, _ = s.MustRun(main, []string{"ds", "-d", datasetName}) 72 s.Equal("Deleted "+datasetName+" (was #ld4fuj44sd4gu0pepn7h5hga72282v81)\n", rtnVal) 73 74 // print datasets, just one left 75 rtnVal, _ = s.MustRun(main, []string{"ds", dbSpec}) 76 s.Equal(id2+"\n", rtnVal) 77 78 // delete the second dataset 79 rtnVal, _ = s.MustRun(main, []string{"ds", "-d", dataset2Name}) 80 s.Equal("Deleted "+dataset2Name+" (was #43qqlvkiainn1jf53g705622nndu1bje)\n", rtnVal) 81 82 // print datasets, none left 83 rtnVal, _ = s.MustRun(main, []string{"ds", dbSpec}) 84 s.Equal("", rtnVal) 85 }