func (s *nomsShowTestSuite) TestTruncation() { toNomsList := func(l []string) types.List { nv := []types.Value{} for _, v := range l { nv = append(nv, types.String(v)) } return types.NewList(nv...) } str := test_util.CreateDatabaseSpecString("ldb", s.LdbDir) dbSpec, err := spec.ParseDatabaseSpec(str) s.NoError(err) db, err := dbSpec.Database() s.NoError(err) t := dataset.NewDataset(db, "truncate") t, err = addCommit(t, "the first line") s.NoError(err) l := []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven"} _, err = addCommitWithValue(t, toNomsList(l)) s.NoError(err) db.Close() dsSpec := test_util.CreateValueSpecString("ldb", s.LdbDir, "truncate") s.Equal(truncRes1, s.Run(main, []string{"-graph", "-show-value=true", dsSpec})) s.Equal(diffTrunc1, s.Run(main, []string{"-graph", "-show-value=false", dsSpec})) s.Equal(truncRes2, s.Run(main, []string{"-graph", "-show-value=true", "-max-lines=-1", dsSpec})) s.Equal(diffTrunc2, s.Run(main, []string{"-graph", "-show-value=false", "-max-lines=-1", dsSpec})) s.Equal(truncRes3, s.Run(main, []string{"-graph", "-show-value=true", "-max-lines=0", dsSpec})) s.Equal(diffTrunc3, s.Run(main, []string{"-graph", "-show-value=false", "-max-lines=0", dsSpec})) }
func (s *nomsShowTestSuite) TestNArg() { str := test_util.CreateDatabaseSpecString("ldb", s.LdbDir) dsName := "nArgTest" dbSpec, err := spec.ParseDatabaseSpec(str) s.NoError(err) db, err := dbSpec.Database() s.NoError(err) ds := dataset.NewDataset(db, dsName) ds, err = addCommit(ds, "1") h1 := ds.Head().Hash() s.NoError(err) ds, err = addCommit(ds, "2") s.NoError(err) h2 := ds.Head().Hash() ds, err = addCommit(ds, "3") s.NoError(err) h3 := ds.Head().Hash() db.Close() dsSpec := test_util.CreateValueSpecString("ldb", s.LdbDir, dsName) s.NotContains(s.Run(main, []string{"-n=1", dsSpec}), h1.String()) res := s.Run(main, []string{"-n=0", dsSpec}) s.Contains(res, h3.String()) s.Contains(res, h2.String()) s.Contains(res, h1.String()) vSpec := test_util.CreateValueSpecString("ldb", s.LdbDir, h3.String()) s.NotContains(s.Run(main, []string{"-n=1", vSpec}), h1.String()) res = s.Run(main, []string{"-n=0", vSpec}) s.Contains(res, h3.String()) s.Contains(res, h2.String()) s.Contains(res, h1.String()) }
func (s *nomsShowTestSuite) TestNomsGraph2() { str := test_util.CreateDatabaseSpecString("ldb", s.LdbDir) dbSpec, err := spec.ParseDatabaseSpec(str) s.NoError(err) db, err := dbSpec.Database() s.NoError(err) ba := dataset.NewDataset(db, "ba") ba, err = addCommit(ba, "1") s.NoError(err) bb := dataset.NewDataset(db, "bb") bb, err = addCommit(bb, "10") s.NoError(err) bc := dataset.NewDataset(db, "bc") bc, err = addCommit(bc, "100") s.NoError(err) ba, err = mergeDatasets(ba, bb, "11") s.NoError(err) _, err = mergeDatasets(ba, bc, "101") s.NoError(err) db.Close() s.Equal(graphRes2, s.Run(main, []string{"-graph", "-show-value=true", test_util.CreateValueSpecString("ldb", s.LdbDir, "ba")})) s.Equal(diffRes2, s.Run(main, []string{"-graph", "-show-value=false", test_util.CreateValueSpecString("ldb", s.LdbDir, "ba")})) }
func (s *testSuite) TestEmptyNomsDs() { dir := s.LdbDir cs := chunks.NewLevelDBStore(dir+"/name", "", 24, false) ds := datas.NewDatabase(cs) ds.Close() dbSpec := test_util.CreateDatabaseSpecString("ldb", dir+"/name") rtnVal := s.Run(main, []string{dbSpec}) s.Equal("", rtnVal) }
func (s *nomsShowTestSuite) TestNomsGraph1() { str := test_util.CreateDatabaseSpecString("ldb", s.LdbDir) dbSpec, err := spec.ParseDatabaseSpec(str) s.NoError(err) db, err := dbSpec.Database() s.NoError(err) b1 := dataset.NewDataset(db, "b1") b1, err = addCommit(b1, "1") s.NoError(err) b1, err = addCommit(b1, "2") s.NoError(err) b1, err = addCommit(b1, "3") s.NoError(err) b2 := dataset.NewDataset(db, "b2") b2, err = addBranchedDataset(b2, b1, "3.1") s.NoError(err) b1, err = addCommit(b1, "3.2") s.NoError(err) b1, err = addCommit(b1, "3.6") s.NoError(err) b3 := dataset.NewDataset(db, "b3") b3, err = addBranchedDataset(b3, b2, "3.1.3") s.NoError(err) b3, err = addCommit(b3, "3.1.5") s.NoError(err) b3, err = addCommit(b3, "3.1.7") s.NoError(err) b2, err = mergeDatasets(b2, b3, "3.5") s.NoError(err) b2, err = addCommit(b2, "3.7") s.NoError(err) b1, err = mergeDatasets(b1, b2, "4") s.NoError(err) b1, err = addCommit(b1, "5") s.NoError(err) b1, err = addCommit(b1, "6") s.NoError(err) b1, err = addCommit(b1, "7") s.NoError(err) b1.Database().Close() s.Equal(graphRes1, s.Run(main, []string{"-graph", "-show-value=true", test_util.CreateValueSpecString("ldb", s.LdbDir, "b1")})) s.Equal(diffRes1, s.Run(main, []string{"-graph", "-show-value=false", test_util.CreateValueSpecString("ldb", s.LdbDir, "b1")})) }
func (s *testSuite) TestNomsDs() { dir := s.LdbDir cs := chunks.NewLevelDBStore(dir+"/name", "", 24, false) ds := datas.NewDatabase(cs) id := "testdataset" set := dataset.NewDataset(ds, id) set, err := set.Commit(types.String("Commit Value")) s.NoError(err) id2 := "testdataset2" set2 := dataset.NewDataset(ds, id2) set2, err = set2.Commit(types.String("Commit Value2")) s.NoError(err) err = ds.Close() s.NoError(err) dbSpec := test_util.CreateDatabaseSpecString("ldb", dir+"/name") datasetName := test_util.CreateValueSpecString("ldb", dir+"/name", id) dataset2Name := test_util.CreateValueSpecString("ldb", dir+"/name", id2) // both datasets show up rtnVal := s.Run(main, []string{dbSpec}) s.Equal(id+"\n"+id2+"\n", rtnVal) // both datasets again, to make sure printing doesn't change them rtnVal = s.Run(main, []string{dbSpec}) s.Equal(id+"\n"+id2+"\n", rtnVal) // delete one dataset, print message at delete rtnVal = s.Run(main, []string{"-d", datasetName}) s.Equal("Deleted dataset "+id+" (was sha1-d54b79552cda9ebe8e446eeb19aab0e69b6ceee3)\n\n", rtnVal) // print datasets, just one left rtnVal = s.Run(main, []string{dbSpec}) s.Equal(id2+"\n", rtnVal) // delete the second dataset rtnVal = s.Run(main, []string{"-d", dataset2Name}) s.Equal("Deleted dataset "+id2+" (was sha1-7b75b0ebfc2a0815ba6fb2b31d03c8f9976ae530)\n\n", rtnVal) // print datasets, none left rtnVal = s.Run(main, []string{dbSpec}) s.Equal("", rtnVal) }
func (s *nomsShowTestSuite) TestNomsGraph3() { str := test_util.CreateDatabaseSpecString("ldb", s.LdbDir) dbSpec, err := spec.ParseDatabaseSpec(str) s.NoError(err) db, err := dbSpec.Database() s.NoError(err) w := dataset.NewDataset(db, "w") w, err = addCommit(w, "1") s.NoError(err) w, err = addCommit(w, "2") s.NoError(err) x := dataset.NewDataset(db, "x") x, err = addBranchedDataset(x, w, "20-x") s.NoError(err) y := dataset.NewDataset(db, "y") y, err = addBranchedDataset(y, w, "200-y") s.NoError(err) z := dataset.NewDataset(db, "z") z, err = addBranchedDataset(z, w, "2000-z") s.NoError(err) w, err = mergeDatasets(w, x, "22-wx") s.NoError(err) w, err = mergeDatasets(w, y, "222-wy") s.NoError(err) _, err = mergeDatasets(w, z, "2222-wz") s.NoError(err) db.Close() s.Equal(graphRes3, s.Run(main, []string{"-graph", "-show-value=true", test_util.CreateValueSpecString("ldb", s.LdbDir, "w")})) s.Equal(diffRes3, s.Run(main, []string{"-graph", "-show-value=false", test_util.CreateValueSpecString("ldb", s.LdbDir, "w")})) }