Skip to content

Commit 5209429

Browse files
committed
use stretcher/testify instead of juju/testing
1 parent 79c8f4e commit 5209429

File tree

5 files changed

+72
-113
lines changed

5 files changed

+72
-113
lines changed

Gopkg.lock

+13-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

diffparser.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
NEW
2424
)
2525

26+
// DiffRange contains the DiffLine's
2627
type DiffRange struct {
2728

2829
// starting line number
@@ -72,7 +73,7 @@ type DiffFile struct {
7273
Hunks []*DiffHunk
7374
}
7475

75-
//Diff is the collection of DiffFiles
76+
// Diff is the collection of DiffFiles
7677
type Diff struct {
7778
Files []*DiffFile
7879
Raw string `sql:"type:text"`

diffparser_test.go

+42-59
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,118 @@
11
// Copyright (c) 2015 Jesse Meek <https://github.com/waigani>
22
// This program is Free Software see LICENSE file for details.
33

4-
package diffparser_test
4+
package diffparser
55

66
import (
77
"io/ioutil"
88
"testing"
99

10-
jt "github.com/juju/testing"
11-
jc "github.com/juju/testing/checkers"
12-
"github.com/waigani/diffparser"
13-
gc "gopkg.in/check.v1"
10+
"github.com/stretchr/testify/require"
1411
)
1512

16-
func Test(t *testing.T) {
17-
gc.TestingT(t)
18-
}
19-
20-
type suite struct {
21-
jt.CleanupSuite
22-
rawdiff string
23-
diff *diffparser.Diff
24-
}
25-
26-
var _ = gc.Suite(&suite{})
27-
28-
func (s *suite) SetUpSuite(c *gc.C) {
29-
byt, err := ioutil.ReadFile("example.diff")
30-
c.Assert(err, jc.ErrorIsNil)
31-
s.rawdiff = string(byt)
32-
}
33-
3413
// TODO(waigani) tests are missing more creative names (spaces, special
3514
// chars), and diffed files that are not in the current directory.
3615

37-
func (s *suite) TestFileModeAndNaming(c *gc.C) {
38-
diff, err := diffparser.Parse(s.rawdiff)
39-
c.Assert(err, jc.ErrorIsNil)
40-
c.Assert(diff.Files, gc.HasLen, 6)
16+
func setup(t *testing.T) *Diff {
17+
byt, err := ioutil.ReadFile("example.diff")
18+
require.NoError(t, err)
19+
20+
diff, err := Parse(string(byt))
21+
require.NoError(t, err)
22+
require.Equal(t, len(diff.Files), 6)
4123

24+
return diff
25+
}
26+
func TestFileModeAndNaming(t *testing.T) {
27+
diff := setup(t)
4228
for i, expected := range []struct {
43-
mode diffparser.FileMode
29+
mode FileMode
4430
origName string
4531
newName string
4632
}{
4733
{
48-
mode: diffparser.MODIFIED,
34+
mode: MODIFIED,
4935
origName: "file1",
5036
newName: "file1",
5137
},
5238
{
53-
mode: diffparser.DELETED,
39+
mode: DELETED,
5440
origName: "file2",
5541
newName: "",
5642
},
5743
{
58-
mode: diffparser.DELETED,
44+
mode: DELETED,
5945
origName: "file3",
6046
newName: "",
6147
},
6248
{
63-
mode: diffparser.NEW,
49+
mode: NEW,
6450
origName: "",
6551
newName: "file4",
6652
},
6753
{
68-
mode: diffparser.NEW,
54+
mode: NEW,
6955
origName: "",
7056
newName: "newname",
7157
},
7258
{
73-
mode: diffparser.DELETED,
59+
mode: DELETED,
7460
origName: "symlink",
7561
newName: "",
7662
},
7763
} {
7864
file := diff.Files[i]
79-
c.Logf("testing file: %v", file)
80-
c.Assert(file.Mode, gc.Equals, expected.mode)
81-
c.Assert(file.OrigName, gc.Equals, expected.origName)
82-
c.Assert(file.NewName, gc.Equals, expected.newName)
65+
t.Logf("testing file: %v", file)
66+
require.Equal(t, expected.mode, file.Mode)
67+
require.Equal(t, expected.origName, file.OrigName)
68+
require.Equal(t, expected.newName, file.NewName)
8369
}
8470
}
8571

86-
func (s *suite) TestHunk(c *gc.C) {
87-
diff, err := diffparser.Parse(s.rawdiff)
88-
c.Assert(err, jc.ErrorIsNil)
89-
c.Assert(diff.Files, gc.HasLen, 6)
90-
91-
expectedOrigLines := []diffparser.DiffLine{
72+
func TestHunk(t *testing.T) {
73+
diff := setup(t)
74+
expectedOrigLines := []DiffLine{
9275
{
93-
Mode: diffparser.UNCHANGED,
76+
Mode: UNCHANGED,
9477
Number: 1,
9578
Content: "some",
9679
Position: 2,
9780
}, {
98-
Mode: diffparser.UNCHANGED,
81+
Mode: UNCHANGED,
9982
Number: 2,
10083
Content: "lines",
10184
Position: 3,
10285
}, {
103-
Mode: diffparser.REMOVED,
86+
Mode: REMOVED,
10487
Number: 3,
10588
Content: "in",
10689
Position: 4,
10790
}, {
108-
Mode: diffparser.UNCHANGED,
91+
Mode: UNCHANGED,
10992
Number: 4,
11093
Content: "file1",
11194
Position: 5,
11295
},
11396
}
11497

115-
expectedNewLines := []diffparser.DiffLine{
98+
expectedNewLines := []DiffLine{
11699
{
117-
Mode: diffparser.ADDED,
100+
Mode: ADDED,
118101
Number: 1,
119102
Content: "add a line",
120103
Position: 1,
121104
}, {
122-
Mode: diffparser.UNCHANGED,
105+
Mode: UNCHANGED,
123106
Number: 2,
124107
Content: "some",
125108
Position: 2,
126109
}, {
127-
Mode: diffparser.UNCHANGED,
110+
Mode: UNCHANGED,
128111
Number: 3,
129112
Content: "lines",
130113
Position: 3,
131114
}, {
132-
Mode: diffparser.UNCHANGED,
115+
Mode: UNCHANGED,
133116
Number: 4,
134117
Content: "file1",
135118
Position: 5,
@@ -140,15 +123,15 @@ func (s *suite) TestHunk(c *gc.C) {
140123
origRange := file.Hunks[0].OrigRange
141124
newRange := file.Hunks[0].NewRange
142125

143-
c.Assert(origRange.Start, gc.Equals, 1)
144-
c.Assert(origRange.Length, gc.Equals, 4)
145-
c.Assert(newRange.Start, gc.Equals, 1)
146-
c.Assert(newRange.Length, gc.Equals, 4)
126+
require.Equal(t, 1, origRange.Start)
127+
require.Equal(t, 4, origRange.Length)
128+
require.Equal(t, 1, newRange.Start)
129+
require.Equal(t, 4, newRange.Length)
147130

148131
for i, line := range expectedOrigLines {
149-
c.Assert(*origRange.Lines[i], gc.DeepEquals, line)
132+
require.Equal(t, line, *origRange.Lines[i])
150133
}
151134
for i, line := range expectedNewLines {
152-
c.Assert(*newRange.Lines[i], gc.DeepEquals, line)
135+
require.Equal(t, line, *newRange.Lines[i])
153136
}
154137
}

go.mod

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ module github.com/waigani/diffparser
33
go 1.12
44

55
require (
6-
github.com/juju/errors v0.0.0-20150916125642-1b5e39b83d18
7-
github.com/juju/loggo v0.0.0-20160511211902-0e0537f18a29
8-
github.com/juju/testing v0.0.0-20160203233110-321edad6b2d1
9-
github.com/juju/utils v0.0.0-20160815113839-bdb77b07e7e3
10-
golang.org/x/crypto v0.0.0-20160824173033-351dc6a5bf92
11-
gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2
12-
gopkg.in/mgo.v2 v2.0.0-20150529124711-01ee097136da
13-
gopkg.in/yaml.v2 v2.0.0-20160715033755-e4d366fc3c79
6+
github.com/davecgh/go-spew v1.1.1
7+
github.com/pmezard/go-difflib v1.0.0
8+
github.com/stretchr/testify v1.4.0
9+
gopkg.in/yaml.v2 v2.2.2
1410
)

go.sum

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
github.com/juju/errors v0.0.0-20150916125642-1b5e39b83d18 h1:Sem5Flzxj8ZdAgY2wfHBUlOYyP4wrpIfM8IZgANNGh8=
2-
github.com/juju/errors v0.0.0-20150916125642-1b5e39b83d18/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
3-
github.com/juju/loggo v0.0.0-20160511211902-0e0537f18a29 h1:wXuXWz7gZy8UQSiFy34IhHOdeV45qSO4fAG3p0DrRRA=
4-
github.com/juju/loggo v0.0.0-20160511211902-0e0537f18a29/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
5-
github.com/juju/testing v0.0.0-20160203233110-321edad6b2d1 h1:0WbpCsj5kC5p6YSWl0Y6THSMeD2eTCx2rLKYQ7/3aS4=
6-
github.com/juju/testing v0.0.0-20160203233110-321edad6b2d1/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
7-
github.com/juju/utils v0.0.0-20160815113839-bdb77b07e7e3 h1:UmZwEQJiCr97I7qMfUB9VqS2BzRNQXx4VuAoHIfTQyA=
8-
github.com/juju/utils v0.0.0-20160815113839-bdb77b07e7e3/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk=
9-
golang.org/x/crypto v0.0.0-20160824173033-351dc6a5bf92 h1:6HmDSTSU7PVgeKBom4W04S2VmgzLOtZlfUiJuF+txm4=
10-
golang.org/x/crypto v0.0.0-20160824173033-351dc6a5bf92/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
11-
gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2 h1:+j1SppRob9bAgoYmsdW9NNBdKZfgYuWpqnYHv78Qt8w=
12-
gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
13-
gopkg.in/mgo.v2 v2.0.0-20150529124711-01ee097136da h1:k2jXxOPVI4OLmisXza2wym08Pz6x+ky/f71oJBuA8zg=
14-
gopkg.in/mgo.v2 v2.0.0-20150529124711-01ee097136da/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
15-
gopkg.in/yaml.v2 v2.0.0-20160715033755-e4d366fc3c79 h1:mENkfeXGmLV7lIyBeNdwYWdONek7pH9yHaHMgZyvIWE=
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
8+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1610
gopkg.in/yaml.v2 v2.0.0-20160715033755-e4d366fc3c79/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
11+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
12+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)