github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/cmd/noms/noms_root_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/spec" 31 "github.com/dolthub/dolt/go/store/types" 32 "github.com/dolthub/dolt/go/store/util/clienttest" 33 ) 34 35 func TestNomsRoot(t *testing.T) { 36 suite.Run(t, &nomsRootTestSuite{}) 37 } 38 39 type nomsRootTestSuite struct { 40 clienttest.ClientTestSuite 41 } 42 43 func (s *nomsRootTestSuite) TestBasic() { 44 datasetName := "root-get" 45 dsSpec := spec.CreateValueSpecString("nbs", s.DBDir, datasetName) 46 sp, err := spec.ForDataset(dsSpec) 47 s.NoError(err) 48 defer sp.Close() 49 50 ds := sp.GetDataset(context.Background()) 51 dbSpecStr := spec.CreateDatabaseSpecString("nbs", s.DBDir) 52 ds, _ = ds.Database().CommitValue(context.Background(), ds, types.String("hello!")) 53 c1, _ := s.MustRun(main, []string{"root", dbSpecStr}) 54 s.Equal("maojl4udo9a7mtk2rnhuc08r0u7hc0fn\n", c1) 55 56 ds, _ = ds.Database().CommitValue(context.Background(), ds, types.String("goodbye")) 57 c2, _ := s.MustRun(main, []string{"root", dbSpecStr}) 58 s.Equal("avdab61n1s1d1emdee7kb7e49quisr5n\n", c2) 59 60 // TODO: Would be good to test successful --update too, but requires changes to MustRun to allow 61 // input because of prompt :(. 62 }