github.com/jbendotnet/noms@v0.0.0-20190904222105-c43e4293ea92/cmd/noms/noms_blob_get_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 "bytes" 9 "fmt" 10 "io/ioutil" 11 "path/filepath" 12 "testing" 13 14 "github.com/attic-labs/noms/go/spec" 15 "github.com/attic-labs/noms/go/types" 16 "github.com/attic-labs/noms/go/util/clienttest" 17 "github.com/stretchr/testify/suite" 18 ) 19 20 func TestNomsBlobGet(t *testing.T) { 21 suite.Run(t, &nbeSuite{}) 22 } 23 24 type nbeSuite struct { 25 clienttest.ClientTestSuite 26 } 27 28 func (s *nbeSuite) TestNomsBlobGet() { 29 sp, err := spec.ForDatabase(s.TempDir) 30 s.NoError(err) 31 defer sp.Close() 32 db := sp.GetDatabase() 33 34 blobBytes := []byte("hello") 35 blob := types.NewBlob(db, bytes.NewBuffer(blobBytes)) 36 37 ref := db.WriteValue(blob) 38 _, err = db.CommitValue(db.GetDataset("datasetID"), ref) 39 s.NoError(err) 40 41 hashSpec := fmt.Sprintf("%s::#%s", s.TempDir, ref.TargetHash().String()) 42 filePath := filepath.Join(s.TempDir, "out") 43 s.MustRun(main, []string{"blob", "export", hashSpec, filePath}) 44 45 fileBytes, err := ioutil.ReadFile(filePath) 46 s.NoError(err) 47 s.Equal(blobBytes, fileBytes) 48 49 stdout, _ := s.MustRun(main, []string{"blob", "export", hashSpec}) 50 fmt.Println("stdout:", stdout) 51 s.Equal(blobBytes, []byte(stdout)) 52 }