github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/cmd/noms/noms_diff_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 "strings" 27 "testing" 28 29 "github.com/stretchr/testify/suite" 30 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 type nomsDiffTestSuite struct { 37 clienttest.ClientTestSuite 38 } 39 40 func TestNomsDiff(t *testing.T) { 41 suite.Run(t, &nomsDiffTestSuite{}) 42 } 43 44 func (s *nomsDiffTestSuite) TestNomsDiffOutputNotTruncated() { 45 sp, err := spec.ForDataset(spec.CreateValueSpecString("nbs", s.DBDir, "diffTest")) 46 s.NoError(err) 47 defer sp.Close() 48 49 ds, err := addCommit(sp.GetDataset(context.Background()), "first commit") 50 s.NoError(err) 51 52 r1 := spec.CreateValueSpecString("nbs", s.DBDir, "#"+mustHeadRef(ds).TargetHash().String()) 53 54 ds, err = addCommit(ds, "second commit") 55 s.NoError(err) 56 r2 := spec.CreateValueSpecString("nbs", s.DBDir, "#"+mustHeadRef(ds).TargetHash().String()) 57 58 out, _ := s.MustRun(main, []string{"diff", r1, r2}) 59 s.True(strings.HasSuffix(out, "\"second commit\"\n }\n"), out) 60 } 61 62 func (s *nomsDiffTestSuite) TestNomsDiffStat() { 63 sp, err := spec.ForDataset(spec.CreateValueSpecString("nbs", s.DBDir, "diffStatTest")) 64 s.NoError(err) 65 defer sp.Close() 66 67 db := sp.GetDatabase(context.Background()) 68 69 ds, err := addCommit(sp.GetDataset(context.Background()), "first commit") 70 s.NoError(err) 71 72 r1 := spec.CreateHashSpecString("nbs", s.DBDir, mustHeadRef(ds).TargetHash()) 73 74 ds, err = addCommit(ds, "second commit") 75 s.NoError(err) 76 r2 := spec.CreateHashSpecString("nbs", s.DBDir, mustHeadRef(ds).TargetHash()) 77 78 out, _ := s.MustRun(main, []string{"diff", "--stat", r1, r2}) 79 s.Contains(out, "Comparing commit values") 80 s.Contains(out, "1 insertion (100.00%), 1 deletion (100.00%), 0 changes (0.00%), (1 value vs 1 value)") 81 82 out, _ = s.MustRun(main, []string{"diff", "--stat", r1 + ".value", r2 + ".value"}) 83 s.NotContains(out, "Comparing commit values") 84 85 l, err := types.NewList(context.Background(), db, types.Float(1), types.Float(2), types.Float(3), types.Float(4)) 86 s.NoError(err) 87 ds, err = db.CommitValue(context.Background(), ds, l) 88 s.NoError(err) 89 90 r3 := spec.CreateHashSpecString("nbs", s.DBDir, mustHeadRef(ds).TargetHash()) + ".value" 91 92 l, err = types.NewList(context.Background(), db, types.Float(1), types.Float(222), types.Float(4)) 93 s.NoError(err) 94 ds, err = db.CommitValue(context.Background(), ds, l) 95 s.NoError(err) 96 r4 := spec.CreateHashSpecString("nbs", s.DBDir, mustHeadRef(ds).TargetHash()) + ".value" 97 98 out, _ = s.MustRun(main, []string{"diff", "--stat", r3, r4}) 99 s.Contains(out, "1 insertion (25.00%), 2 deletions (50.00%), 0 changes (0.00%), (4 values vs 3 values)") 100 }