github.com/attic-labs/noms@v0.0.0-20210827224422-e5fa29d95e8b/cmd/noms/noms_diff_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 "testing" 9 10 "strings" 11 12 "github.com/attic-labs/noms/go/spec" 13 "github.com/attic-labs/noms/go/types" 14 "github.com/attic-labs/noms/go/util/clienttest" 15 "github.com/stretchr/testify/suite" 16 ) 17 18 type nomsDiffTestSuite struct { 19 clienttest.ClientTestSuite 20 } 21 22 func TestNomsDiff(t *testing.T) { 23 suite.Run(t, &nomsDiffTestSuite{}) 24 } 25 26 func (s *nomsDiffTestSuite) TestNomsDiffOutputNotTruncated() { 27 sp, err := spec.ForDataset(spec.CreateValueSpecString("nbs", s.DBDir, "diffTest")) 28 s.NoError(err) 29 defer sp.Close() 30 31 ds, err := addCommit(sp.GetDataset(), "first commit") 32 s.NoError(err) 33 r1 := spec.CreateValueSpecString("nbs", s.DBDir, "#"+ds.HeadRef().TargetHash().String()) 34 35 ds, err = addCommit(ds, "second commit") 36 s.NoError(err) 37 r2 := spec.CreateValueSpecString("nbs", s.DBDir, "#"+ds.HeadRef().TargetHash().String()) 38 39 out, _ := s.MustRun(main, []string{"diff", r1, r2}) 40 s.True(strings.HasSuffix(out, "\"second commit\"\n }\n"), out) 41 } 42 43 func (s *nomsDiffTestSuite) TestNomsDiffStat() { 44 sp, err := spec.ForDataset(spec.CreateValueSpecString("nbs", s.DBDir, "diffStatTest")) 45 s.NoError(err) 46 defer sp.Close() 47 48 db := sp.GetDatabase() 49 50 ds, err := addCommit(sp.GetDataset(), "first commit") 51 s.NoError(err) 52 r1 := spec.CreateHashSpecString("nbs", s.DBDir, ds.HeadRef().TargetHash()) 53 54 ds, err = addCommit(ds, "second commit") 55 s.NoError(err) 56 r2 := spec.CreateHashSpecString("nbs", s.DBDir, ds.HeadRef().TargetHash()) 57 58 out, _ := s.MustRun(main, []string{"diff", "--stat", r1, r2}) 59 s.Contains(out, "Comparing commit values") 60 s.Contains(out, "1 insertion (100.00%), 1 deletion (100.00%), 0 changes (0.00%), (1 value vs 1 value)") 61 62 out, _ = s.MustRun(main, []string{"diff", "--stat", r1 + ".value", r2 + ".value"}) 63 s.NotContains(out, "Comparing commit values") 64 65 ds, err = db.CommitValue(ds, types.NewList(db, types.Number(1), types.Number(2), types.Number(3), types.Number(4))) 66 s.NoError(err) 67 r3 := spec.CreateHashSpecString("nbs", s.DBDir, ds.HeadRef().TargetHash()) + ".value" 68 69 ds, err = db.CommitValue(ds, types.NewList(db, types.Number(1), types.Number(222), types.Number(4))) 70 s.NoError(err) 71 r4 := spec.CreateHashSpecString("nbs", s.DBDir, ds.HeadRef().TargetHash()) + ".value" 72 73 out, _ = s.MustRun(main, []string{"diff", "--stat", r3, r4}) 74 s.Contains(out, "1 insertion (25.00%), 2 deletions (50.00%), 0 changes (0.00%), (4 values vs 3 values)") 75 }