Exemplo n.º 1
0
func (s *testSuite) TestCSVImporterFromBlob() {
	test := func(pathFlag string) {
		defer os.RemoveAll(s.LdbDir)

		newDB := func() datas.Database {
			cs := chunks.NewLevelDBStore(s.LdbDir, "", 1, false)
			return datas.NewDatabase(cs)
		}

		db := newDB()
		rawDS := dataset.NewDataset(db, "raw")
		csv := &bytes.Buffer{}
		writeCSV(csv)
		rawDS.CommitValue(types.NewBlob(csv))
		db.Close()

		stdout, stderr := s.Run(main, []string{
			"--no-progress", "--column-types", "String,Number",
			pathFlag, spec.CreateValueSpecString("ldb", s.LdbDir, "raw.value"),
			spec.CreateValueSpecString("ldb", s.LdbDir, "csv"),
		})
		s.Equal("", stdout)
		s.Equal("", stderr)

		db = newDB()
		defer db.Close()
		csvDS := dataset.NewDataset(db, "csv")
		validateCSV(s, csvDS.HeadValue().(types.List))
	}
	test("--path")
	test("-p")
}
Exemplo n.º 2
0
func (s *nomsSyncTestSuite) TestSync() {
	source1 := dataset.NewDataset(datas.NewDatabase(chunks.NewLevelDBStore(s.LdbDir, "", 1, false)), "foo")
	source1, err := source1.CommitValue(types.Number(42))
	s.NoError(err)
	source2, err := source1.CommitValue(types.Number(43))
	s.NoError(err)
	source1HeadRef := source1.Head().Hash()
	source2.Database().Close() // Close Database backing both Datasets

	sourceSpec := spec.CreateValueSpecString("ldb", s.LdbDir, "#"+source1HeadRef.String())
	ldb2dir := path.Join(s.TempDir, "ldb2")
	sinkDatasetSpec := spec.CreateValueSpecString("ldb", ldb2dir, "bar")
	s.Run(main, []string{"sync", sourceSpec, sinkDatasetSpec})

	dest := dataset.NewDataset(datas.NewDatabase(chunks.NewLevelDBStore(ldb2dir, "", 1, false)), "bar")
	s.True(types.Number(42).Equals(dest.HeadValue()))
	dest.Database().Close()

	sourceDataset := spec.CreateValueSpecString("ldb", s.LdbDir, "foo")
	s.Run(main, []string{"sync", sourceDataset, sinkDatasetSpec})

	dest = dataset.NewDataset(datas.NewDatabase(chunks.NewLevelDBStore(ldb2dir, "", 1, false)), "bar")
	s.True(types.Number(43).Equals(dest.HeadValue()))
	dest.Database().Close()

}
Exemplo n.º 3
0
func (s *nomsLogTestSuite) TestNArg() {
	str := spec.CreateDatabaseSpecString("ldb", s.LdbDir)
	dsName := "nArgTest"
	db, err := spec.GetDatabase(str)
	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 := spec.CreateValueSpecString("ldb", s.LdbDir, dsName)
	res, _ := s.Run(main, []string{"log", "-n1", dsSpec})
	s.NotContains(res, h1.String())
	res, _ = s.Run(main, []string{"log", "-n0", dsSpec})
	s.Contains(res, h3.String())
	s.Contains(res, h2.String())
	s.Contains(res, h1.String())

	vSpec := spec.CreateValueSpecString("ldb", s.LdbDir, "#"+h3.String())
	res, _ = s.Run(main, []string{"log", "-n1", vSpec})
	s.NotContains(res, h1.String())
	res, _ = s.Run(main, []string{"log", "-n0", vSpec})
	s.Contains(res, h3.String())
	s.Contains(res, h2.String())
	s.Contains(res, h1.String())
}
Exemplo n.º 4
0
func (s *nomsShowTestSuite) TestNomsShow() {
	datasetName := "dsTest"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	s1 := types.String("test string")
	r := writeTestData(str, s1)
	res, _ := s.Run(main, []string{"show", str})
	s.Equal(res1, res)

	str1 := spec.CreateValueSpecString("ldb", s.LdbDir, "#"+r.TargetHash().String())
	res, _ = s.Run(main, []string{"show", str1})
	s.Equal(res2, res)

	list := types.NewList(types.String("elem1"), types.Number(2), types.String("elem3"))
	r = writeTestData(str, list)
	res, _ = s.Run(main, []string{"show", str})
	test.EqualsIgnoreHashes(s.T(), res3, res)

	str1 = spec.CreateValueSpecString("ldb", s.LdbDir, "#"+r.TargetHash().String())
	res, _ = s.Run(main, []string{"show", str1})
	s.Equal(res4, res)

	_ = writeTestData(str, s1)
	res, _ = s.Run(main, []string{"show", str})
	test.EqualsIgnoreHashes(s.T(), res5, res)
}
Exemplo n.º 5
0
func (s *nomsLogTestSuite) TestNomsGraph2() {
	str := spec.CreateDatabaseSpecString("ldb", s.LdbDir)
	db, err := spec.GetDatabase(str)
	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()

	res, _ := s.Run(main, []string{"log", "--graph", "--show-value=true", spec.CreateValueSpecString("ldb", s.LdbDir, "ba")})
	s.Equal(graphRes2, res)
	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=false", spec.CreateValueSpecString("ldb", s.LdbDir, "ba")})
	s.Equal(diffRes2, res)
}
Exemplo n.º 6
0
func (s *nomsLogTestSuite) TestNomsGraph1() {
	str := spec.CreateDatabaseSpecString("ldb", s.LdbDir)
	db, err := spec.GetDatabase(str)
	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()
	res, _ := s.Run(main, []string{"log", "--graph", "--show-value=true", spec.CreateValueSpecString("ldb", s.LdbDir, "b1")})
	s.Equal(graphRes1, res)
	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=false", spec.CreateValueSpecString("ldb", s.LdbDir, "b1")})
	s.Equal(diffRes1, res)
}
Exemplo n.º 7
0
func (s *nomsDiffTestSuite) TestNomsDiffSummarize() {
	datasetName := "diffSummarizeTest"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)
	ds, err := spec.GetDataset(str)
	s.NoError(err)
	defer ds.Database().Close()

	ds, err = addCommit(ds, "first commit")
	s.NoError(err)
	r1 := spec.CreateHashSpecString("ldb", s.LdbDir, ds.HeadRef().TargetHash())

	ds, err = addCommit(ds, "second commit")
	s.NoError(err)
	r2 := spec.CreateHashSpecString("ldb", s.LdbDir, ds.HeadRef().TargetHash())

	out, _ := s.Run(main, []string{"diff", "--summarize", r1, r2})
	s.Contains(out, "Comparing commit values")
	s.Contains(out, "1 insertion (100.00%), 1 deletion (100.00%), 0 changes (0.00%), (1 value vs 1 value)")

	out, _ = s.Run(main, []string{"diff", "--summarize", r1 + ".value", r2 + ".value"})
	s.NotContains(out, "Comparing commit values")

	ds, err = ds.CommitValue(types.NewList(types.Number(1), types.Number(2), types.Number(3), types.Number(4)))
	s.NoError(err)
	r3 := spec.CreateHashSpecString("ldb", s.LdbDir, ds.HeadRef().TargetHash()) + ".value"

	ds, err = ds.CommitValue(types.NewList(types.Number(1), types.Number(222), types.Number(4)))
	s.NoError(err)
	r4 := spec.CreateHashSpecString("ldb", s.LdbDir, ds.HeadRef().TargetHash()) + ".value"

	out, _ = s.Run(main, []string{"diff", "--summarize", r3, r4})
	s.Contains(out, "1 insertion (25.00%), 2 deletions (50.00%), 0 changes (0.00%), (4 values vs 3 values)")
}
Exemplo n.º 8
0
func (s *fuseTestSuite) TestSimpleFile() {
	datasetName := "TestSimpleFile"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	file, code := testfs.Create("coconut", uint32(os.O_CREATE|os.O_RDWR), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)
	n, code := file.Write([]byte("Lime!"), 0)
	assert.Equal(s.T(), uint32(5), n)
	assertAttr(s, testfs, "coconut", 0644|fuse.S_IFREG, 5)

	data := make([]byte, 5)
	rr, code := file.Read(data, 0)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), 5, rr.Size())
	assert.Equal(s.T(), "Lime!", string(data))

	code = testfs.Truncate("coconut", 4, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "coconut", 0644|fuse.S_IFREG, 4)
	rr, code = file.Read(data, 0)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), 4, rr.Size())
	assert.Equal(s.T(), "Lime!", string(data))
}
Exemplo n.º 9
0
func (s *testSuite) TestCSVImporterWithPipe() {
	input, err := ioutil.TempFile(s.TempDir, "")
	d.Chk.NoError(err)
	defer input.Close()
	defer os.Remove(input.Name())

	_, err = input.WriteString("a|b\n1|2\n")
	d.Chk.NoError(err)

	setName := "csv"
	dataspec := spec.CreateValueSpecString("ldb", s.LdbDir, setName)
	stdout, stderr := s.Run(main, []string{"--no-progress", "--column-types", "String,Number", "--delimiter", "|", input.Name(), dataspec})
	s.Equal("", stdout)
	s.Equal("", stderr)

	cs := chunks.NewLevelDBStore(s.LdbDir, "", 1, false)
	ds := dataset.NewDataset(datas.NewDatabase(cs), setName)
	defer ds.Database().Close()
	defer os.RemoveAll(s.LdbDir)

	l := ds.HeadValue().(types.List)
	s.Equal(uint64(1), l.Len())
	v := l.Get(0)
	st := v.(types.Struct)
	s.Equal(types.String("1"), st.Get("a"))
	s.Equal(types.Number(2), st.Get("b"))
}
Exemplo n.º 10
0
func (s *testSuite) TestImportFromFile() {
	assert := s.Assert()

	f, err := ioutil.TempFile("", "TestImportFromFile")
	assert.NoError(err)

	f.Write([]byte("abcdef"))
	f.Close()

	dsName := spec.CreateValueSpecString("ldb", s.LdbDir, "ds")
	s.Run(main, []string{f.Name(), dsName})

	db, blob, err := spec.GetPath(dsName + ".value")
	assert.NoError(err)

	expected := types.NewBlob(bytes.NewBufferString("abcdef"))
	assert.True(expected.Equals(blob))

	meta := db.Head("ds").Get(datas.MetaField).(types.Struct)
	metaDesc := meta.Type().Desc.(types.StructDesc)
	assert.Equal(2, metaDesc.Len())
	assert.NotNil(metaDesc.Field("date"))
	assert.Equal(f.Name(), string(meta.Get("file").(types.String)))

	db.Close()
}
Exemplo n.º 11
0
func (s *testSuite) TestCSVImportSkipRecordsCustomHeader() {
	input, err := ioutil.TempFile(s.TempDir, "")
	d.Chk.NoError(err)
	defer input.Close()
	defer os.Remove(input.Name())

	_, err = input.WriteString("a,b\n")
	d.Chk.NoError(err)

	_, err = input.WriteString("7,8\n")
	d.Chk.NoError(err)

	setName := "csv"
	dataspec := spec.CreateValueSpecString("ldb", s.LdbDir, setName)
	stdout, stderr := s.Run(main, []string{"--no-progress", "--skip-records", "1", "--header", "x,y", input.Name(), dataspec})
	s.Equal("", stdout)
	s.Equal("", stderr)

	cs := chunks.NewLevelDBStore(s.LdbDir, "", 1, false)
	ds := dataset.NewDataset(datas.NewDatabase(cs), setName)
	defer ds.Database().Close()
	defer os.RemoveAll(s.LdbDir)

	l := ds.HeadValue().(types.List)
	s.Equal(uint64(1), l.Len())
	v := l.Get(0)
	st := v.(types.Struct)
	s.Equal(types.String("7"), st.Get("x"))
	s.Equal(types.String("8"), st.Get("y"))
}
Exemplo n.º 12
0
func (s *testSuite) TestImportFromStdin() {
	assert := s.Assert()

	oldStdin := os.Stdin
	newStdin, blobOut, err := os.Pipe()
	assert.NoError(err)

	os.Stdin = newStdin
	defer func() {
		os.Stdin = oldStdin
	}()

	go func() {
		blobOut.Write([]byte("abcdef"))
		blobOut.Close()
	}()

	dsName := spec.CreateValueSpecString("ldb", s.LdbDir, "ds")
	// Run() will return when blobOut is closed.
	s.Run(main, []string{"--stdin", dsName})

	db, blob, err := spec.GetPath(dsName + ".value")
	assert.NoError(err)

	expected := types.NewBlob(bytes.NewBufferString("abcdef"))
	assert.True(expected.Equals(blob))

	meta := db.Head("ds").Get(datas.MetaField).(types.Struct)
	// The meta should only have a "date" field.
	metaDesc := meta.Type().Desc.(types.StructDesc)
	assert.Equal(1, metaDesc.Len())
	assert.NotNil(metaDesc.Field("date"))

	db.Close()
}
Exemplo n.º 13
0
func (s *nomsDsTestSuite) 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.CommitValue(types.String("Commit Value"))
	s.NoError(err)

	id2 := "testdataset2"
	set2 := dataset.NewDataset(ds, id2)
	set2, err = set2.CommitValue(types.String("Commit Value2"))
	s.NoError(err)

	err = ds.Close()
	s.NoError(err)

	dbSpec := spec.CreateDatabaseSpecString("ldb", dir+"/name")
	datasetName := spec.CreateValueSpecString("ldb", dir+"/name", id)
	dataset2Name := spec.CreateValueSpecString("ldb", dir+"/name", id2)

	// both datasets show up
	rtnVal, _ := s.Run(main, []string{"ds", dbSpec})
	s.Equal(id+"\n"+id2+"\n", rtnVal)

	// both datasets again, to make sure printing doesn't change them
	rtnVal, _ = s.Run(main, []string{"ds", dbSpec})
	s.Equal(id+"\n"+id2+"\n", rtnVal)

	// delete one dataset, print message at delete
	rtnVal, _ = s.Run(main, []string{"ds", "-d", datasetName})
	s.Equal("Deleted "+datasetName+" (was #6ebc05f71q4sk2psi534fom9se228161)\n", rtnVal)

	// print datasets, just one left
	rtnVal, _ = s.Run(main, []string{"ds", dbSpec})
	s.Equal(id2+"\n", rtnVal)

	// delete the second dataset
	rtnVal, _ = s.Run(main, []string{"ds", "-d", dataset2Name})
	s.Equal("Deleted "+dataset2Name+" (was #f5qtovr9mv7mjj2uoq7flcfpksgf0s2j)\n", rtnVal)

	// print datasets, none left
	rtnVal, _ = s.Run(main, []string{"ds", dbSpec})
	s.Equal("", rtnVal)
}
Exemplo n.º 14
0
func (s *nomsSyncTestSuite) TestSyncValidation() {
	source1 := dataset.NewDataset(datas.NewDatabase(chunks.NewLevelDBStore(s.LdbDir, "", 1, false)), "src")
	source1, err := source1.CommitValue(types.Number(42))
	s.NoError(err)
	source1HeadRef := source1.Head().Hash()
	source1.Database().Close()
	sourceSpecMissingHashSymbol := spec.CreateValueSpecString("ldb", s.LdbDir, source1HeadRef.String())

	ldb2dir := path.Join(s.TempDir, "ldb2")
	sinkDatasetSpec := spec.CreateValueSpecString("ldb", ldb2dir, "dest")

	defer func() {
		err := recover()
		s.Equal(exitError{-1}, err)
	}()

	s.Run(main, []string{"sync", sourceSpecMissingHashSymbol, sinkDatasetSpec})
}
Exemplo n.º 15
0
func (s *nomsDiffTestSuite) TestNomsDiffOutputNotTruncated() {
	datasetName := "diffTest"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)
	ds, err := spec.GetDataset(str)
	s.NoError(err)

	ds, err = addCommit(ds, "first commit")
	s.NoError(err)
	r1 := spec.CreateValueSpecString("ldb", s.LdbDir, "#"+ds.HeadRef().TargetHash().String())

	ds, err = addCommit(ds, "second commit")
	s.NoError(err)
	r2 := spec.CreateValueSpecString("ldb", s.LdbDir, "#"+ds.HeadRef().TargetHash().String())

	ds.Database().Close()
	out, _ := s.Run(main, []string{"diff", r1, r2})
	s.True(strings.HasSuffix(out, "\"second commit\"\n  }\n"), out)
}
Exemplo n.º 16
0
func (s *nomsLogTestSuite) TestNomsLog() {
	datasetName := "dsTest"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)
	ds, err := spec.GetDataset(str)
	s.NoError(err)

	ds.Database().Close()
	s.Panics(func() { s.Run(main, []string{"log", str}) })

	testCommitInResults(s, str, 1)
	testCommitInResults(s, str, 2)
}
Exemplo n.º 17
0
func (s *fuseTestSuite) TestFile() {
	datasetName := "TestFile"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	_, code := testfs.Create("pokemon.go", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "pokemon.go", 0644|fuse.S_IFREG, 0)
}
Exemplo n.º 18
0
func (s *fuseTestSuite) TestDir() {
	datasetName := "TestDir"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("noms", 0777, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "noms", 0777|fuse.S_IFDIR, 0)
}
Exemplo n.º 19
0
func (s *nomsLogTestSuite) TestNomsGraph3() {
	str := spec.CreateDatabaseSpecString("ldb", s.LdbDir)
	db, err := spec.GetDatabase(str)
	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()
	res, _ := s.Run(main, []string{"log", "--graph", "--show-value=true", spec.CreateValueSpecString("ldb", s.LdbDir, "w")})
	test.EqualsIgnoreHashes(s.T(), graphRes3, res)
	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=false", spec.CreateValueSpecString("ldb", s.LdbDir, "w")})
	test.EqualsIgnoreHashes(s.T(), diffRes3, res)
}
Exemplo n.º 20
0
// FIXME: run with pipe
func (s *testSuite) TestCSVExporter() {
	setName := "csv"
	header := []string{"a", "b", "c"}
	payload := [][]string{
		[]string{"5", "7", "100"},
		[]string{"4", "10", "255"},
		[]string{"512", "12", "55"},
	}
	structName := "SomeStruct"

	// Setup data store
	cs := chunks.NewLevelDBStore(s.LdbDir, "", 1, false)
	ds := dataset.NewDataset(datas.NewDatabase(cs), setName)

	typ := types.MakeStructType(structName, header, []*types.Type{
		types.StringType, types.StringType, types.StringType,
	})

	// Build data rows
	structs := make([]types.Value, len(payload))
	for i, row := range payload {
		fields := make(types.ValueSlice, len(header))
		for j, v := range row {
			fields[j] = types.String(v)
		}
		structs[i] = types.NewStructWithType(typ, fields)
	}

	ds.CommitValue(types.NewList(structs...))
	ds.Database().Close()

	// Run exporter
	dataspec := spec.CreateValueSpecString("ldb", s.LdbDir, setName)
	stdout, stderr := s.Run(main, []string{dataspec})
	s.Equal("", stderr)

	// Verify output
	csvReader := csv.NewReader(strings.NewReader(stdout))

	row, err := csvReader.Read()
	d.Chk.NoError(err)
	s.Equal(header, row)

	for i := 0; i < len(payload); i++ {
		row, err := csvReader.Read()
		d.Chk.NoError(err)
		s.Equal(payload[i], row)
	}

	_, err = csvReader.Read()
	s.Equal(io.EOF, err)
}
Exemplo n.º 21
0
func (s *counterTestSuite) TestCounter() {
	spec := spec.CreateValueSpecString("ldb", s.LdbDir, "counter")
	args := []string{spec}
	stdout, stderr := s.Run(main, args)
	s.Equal("1\n", stdout)
	s.Equal("", stderr)
	stdout, stderr = s.Run(main, args)
	s.Equal("2\n", stdout)
	s.Equal("", stderr)
	stdout, stderr = s.Run(main, args)
	s.Equal("3\n", stdout)
	s.Equal("", stderr)
}
Exemplo n.º 22
0
func (s *fuseTestSuite) TestRmdir() {
	datasetName := "TestRmdir"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("wikileaks", 0755, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 1) // 1 means it's there
	code = testfs.Rmdir("wikileaks", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 0) // 0 means no entries
}
Exemplo n.º 23
0
func (s *fuseTestSuite) TestUnlink() {
	datasetName := "TestUnlink"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	_, code := testfs.Create("dilma", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0755, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 1) // 1 means it's there
	code = testfs.Unlink("dilma", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 0) // 0 means no entries
}
Exemplo n.º 24
0
func (s *fuseTestSuite) TestSymlink() {
	datasetName := "TestSymlink"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Symlink("there", "here", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "here", 0755|fuse.S_IFLNK, 0)
	value, code := testfs.Readlink("here", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), "there", value)
}
Exemplo n.º 25
0
func (s *fuseTestSuite) TestDirError() {
	datasetName := "TestDirError"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("foo/bar", 0755, nil)
	assert.Equal(s.T(), fuse.ENOENT, code)
	_, code = testfs.Create("foo", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)
	code = testfs.Mkdir("foo/bar", 0755, nil)
	assert.Equal(s.T(), fuse.ENOTDIR, code)

	_, code = testfs.OpenDir("foo", nil)
	assert.Equal(s.T(), fuse.ENOTDIR, code)
}
Exemplo n.º 26
0
func (s *fuseTestSuite) TestFileInDir() {
	datasetName := "TestFile"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("usr", 0555, nil)
	assert.Equal(s.T(), fuse.OK, code)
	code = testfs.Mkdir("usr/sbin", 0555, nil)
	assert.Equal(s.T(), fuse.OK, code)
	_, code = testfs.Create("usr/sbin/dtrace", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0555, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "usr", 0555|fuse.S_IFDIR, 1)
	assertAttr(s, testfs, "usr/sbin", 0555|fuse.S_IFDIR, 1)
	assertAttr(s, testfs, "usr/sbin/dtrace", 0555|fuse.S_IFREG, 0)
}
Exemplo n.º 27
0
func (s *testSuite) TestCSVImporter() {
	input, err := ioutil.TempFile(s.TempDir, "")
	d.Chk.NoError(err)
	writeCSV(input)
	defer input.Close()
	defer os.Remove(input.Name())

	setName := "csv"
	dataspec := spec.CreateValueSpecString("ldb", s.LdbDir, setName)
	stdout, stderr := s.Run(main, []string{"--no-progress", "--column-types", "String,Number", input.Name(), dataspec})
	s.Equal("", stdout)
	s.Equal("", stderr)

	cs := chunks.NewLevelDBStore(s.LdbDir, "", 1, false)
	ds := dataset.NewDataset(datas.NewDatabase(cs), setName)
	defer ds.Database().Close()
	defer os.RemoveAll(s.LdbDir)

	validateCSV(s, ds.HeadValue().(types.List))
}
Exemplo n.º 28
0
func (s *fuseTestSuite) TestHierarchy() {
	datasetName := "TestHierarchy"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	hierarchy := []string{
		"bin/",
		"bin/sh",
		"usr/",
		"usr/bin/",
		"usr/bin/cat",
		"usr/bin/bash",
		"usr/lib/",
		"usr/lib/libc.so.1",
		"usr/dict/",
		"usr/dict/words",
		"usr/dict/words2",
	}

	for _, path := range hierarchy {
		if ll := len(path); path[ll-1] == '/' {
			code := testfs.Mkdir(path[:ll-1], 0555, nil)
			assert.Equal(s.T(), fuse.OK, code)
		} else {
			_, code := testfs.Create(path, uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0444, nil)
			assert.Equal(s.T(), fuse.OK, code)
		}
	}

	h := find(testfs)

	sort.Strings(hierarchy)
	sort.Strings(h)

	assert.Equal(s.T(), hierarchy, h)
}
Exemplo n.º 29
0
func (s *nomsLogTestSuite) 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 := spec.CreateDatabaseSpecString("ldb", s.LdbDir)
	db, err := spec.GetDatabase(str)
	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 := spec.CreateValueSpecString("ldb", s.LdbDir, "truncate")
	res, _ := s.Run(main, []string{"log", "--graph", "--show-value=true", dsSpec})
	test.EqualsIgnoreHashes(s.T(), truncRes1, res)
	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=false", dsSpec})
	test.EqualsIgnoreHashes(s.T(), diffTrunc1, res)

	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=true", "--max-lines=-1", dsSpec})
	test.EqualsIgnoreHashes(s.T(), truncRes2, res)
	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=false", "--max-lines=-1", dsSpec})
	test.EqualsIgnoreHashes(s.T(), diffTrunc2, res)

	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=true", "--max-lines=0", dsSpec})
	test.EqualsIgnoreHashes(s.T(), truncRes3, res)
	res, _ = s.Run(main, []string{"log", "--graph", "--show-value=false", "--max-lines=0", dsSpec})
	test.EqualsIgnoreHashes(s.T(), diffTrunc3, res)
}
Exemplo n.º 30
0
func (s *fuseTestSuite) TestBigFile() {
	datasetName := "TestBigFile"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	size := uint64(10 * 1024) // 10KB
	data := make([]byte, size)
	buf := bytes.NewBuffer(data)

	for uint64(buf.Len()) < size {
		buf.WriteString("All work and no play makes Jack a dull boy.\n")
	}

	file, code := testfs.Create("shining.txt", uint32(os.O_CREATE|os.O_RDWR), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)

	n, code := file.Write(buf.Bytes(), 0)
	assert.Equal(s.T(), uint32(size), n)
	assertAttr(s, testfs, "shining.txt", 0644|fuse.S_IFREG, size)
}