github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/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/datas"
    31  	"github.com/dolthub/dolt/go/store/spec"
    32  	"github.com/dolthub/dolt/go/store/types"
    33  	"github.com/dolthub/dolt/go/store/util/clienttest"
    34  )
    35  
    36  func TestNomsRoot(t *testing.T) {
    37  	suite.Run(t, &nomsRootTestSuite{})
    38  }
    39  
    40  type nomsRootTestSuite struct {
    41  	clienttest.ClientTestSuite
    42  }
    43  
    44  func (s *nomsRootTestSuite) TestBasic() {
    45  	datasetName := "root-get"
    46  	dsSpec := spec.CreateValueSpecString("nbs", s.DBDir, datasetName)
    47  	sp, err := spec.ForDataset(dsSpec)
    48  	s.NoError(err)
    49  	defer sp.Close()
    50  
    51  	ds := sp.GetDataset(context.Background())
    52  	dbSpecStr := spec.CreateDatabaseSpecString("nbs", s.DBDir)
    53  	db := ds.Database()
    54  
    55  	var goldenHello, goldenGoodbye string
    56  	switch types.Format_Default {
    57  	case types.Format_DOLT:
    58  		goldenHello = "sf173aaa57qjoakme0iufkg4c17beoqe\n"
    59  		goldenGoodbye = "gjcehnn4v0sbtt1hste082hfv1kg0hqv\n"
    60  	case types.Format_LD_1:
    61  		goldenHello = "u8g2r4qg97kkqn42lvao77st2mv3bpl0\n"
    62  		goldenGoodbye = "70b9adi6amrab3a5t4hcibdob0cq49m0\n"
    63  	default:
    64  		s.Fail("no golden values exist for NBF %s", types.Format_Default.VersionString())
    65  	}
    66  
    67  	ds, _ = datas.CommitValue(context.Background(), db, ds, types.String("hello!"))
    68  	c1, _ := s.MustRun(main, []string{"root", dbSpecStr})
    69  	s.Equal(goldenHello, c1)
    70  
    71  	ds, _ = datas.CommitValue(context.Background(), db, ds, types.String("goodbye"))
    72  	c2, _ := s.MustRun(main, []string{"root", dbSpecStr})
    73  	s.Equal(goldenGoodbye, c2)
    74  
    75  	// TODO: Would be good to test successful --update too, but requires changes to MustRun to allow
    76  	// input because of prompt :(.
    77  }