Skip to content

Commit 1f184ad

Browse files
committed
rewrite e2e test in go
1 parent aef4504 commit 1f184ad

File tree

7 files changed

+110
-28
lines changed

7 files changed

+110
-28
lines changed

Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ all: build
33
build:
44
@go build
55

6-
test: all
7-
go test -tags=online ./...
8-
./e2e.sh
6+
test:
7+
go test -tags=online,e2e ./...
98

109
install:
1110
@go install

e2e.sh

-14
This file was deleted.

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/dmgk/modules2tuple
22

33
go 1.13
4+
5+
require github.com/sergi/go-diff v1.1.0

go.sum

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
5+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
6+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
7+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
8+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
12+
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
13+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
14+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
15+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
16+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
17+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
18+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
20+
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
21+
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

parser/parser_e2e_test.go

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// +build e2e
2+
3+
package parser
4+
5+
import (
6+
"fmt"
7+
"io/ioutil"
8+
"path/filepath"
9+
"strings"
10+
"testing"
11+
12+
"github.com/sergi/go-diff/diffmatchpatch"
13+
)
14+
15+
const testdataPath = "../testdata"
16+
17+
type example struct {
18+
modules, expected string
19+
}
20+
21+
func TestParserE2E(t *testing.T) {
22+
examples, err := loadExamples()
23+
if err != nil {
24+
t.Fatal(err)
25+
}
26+
27+
for n, x := range examples {
28+
expected, err := ioutil.ReadFile(x.expected)
29+
if err != nil {
30+
t.Fatal(err)
31+
}
32+
33+
actual, err := Load(x.modules)
34+
if err != nil {
35+
t.Fatal(err)
36+
}
37+
38+
dmp := diffmatchpatch.New()
39+
diffs := dmp.DiffMain(strings.TrimSpace(string(expected)), strings.TrimSpace(actual.String()), false)
40+
if dmp.DiffLevenshtein(diffs) > 0 {
41+
t.Errorf("%s: expected output doesn't match actual:\n%s", n, dmp.DiffPrettyText(diffs))
42+
}
43+
}
44+
}
45+
46+
func loadExamples() (map[string]*example, error) {
47+
res := map[string]*example{}
48+
49+
dir, err := ioutil.ReadDir(testdataPath)
50+
if err != nil {
51+
return nil, err
52+
}
53+
54+
for _, f := range dir {
55+
name := f.Name()
56+
parts := strings.SplitN(strings.TrimSuffix(name, filepath.Ext(name)), "_", 2)
57+
if len(parts) < 2 {
58+
return nil, fmt.Errorf("unexpected testdata file name: %q", name)
59+
}
60+
key, kind := parts[0], parts[1]
61+
62+
x, ok := res[key]
63+
if !ok {
64+
x = &example{}
65+
res[key] = x
66+
}
67+
switch kind {
68+
case "modules":
69+
x.modules = filepath.Join(testdataPath, name)
70+
case "expected":
71+
x.expected = filepath.Join(testdataPath, name)
72+
default:
73+
return nil, fmt.Errorf("unexpected testdata file name: %q", name)
74+
}
75+
}
76+
77+
return res, nil
78+
}

parser/parser_offline_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !online
1+
// +build !online,!e2e
22

33
package parser
44

tuple/tuple.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ type Tuple struct {
106106
source Source // tuple source (Github ot Gitlab)
107107
account string // source account
108108
project string // source project
109-
hidden bool
109+
hidden bool // if true, tuple will be excluded from G{H,L}_TUPLE
110110
}
111111

112112
var underscoreRe = regexp.MustCompile(`[^\w]+`)
@@ -363,14 +363,6 @@ func fixGithubProjectsAndTags(s Slice) error {
363363
return nil
364364
}
365365

366-
// func reverseVersion(v string) string {
367-
// parts := strings.Split(v, "/")
368-
// for i, j := 0, len(parts)-1; i < j; i, j = i+1, j-1 {
369-
// parts[i], parts[j] = parts[j], parts[i]
370-
// }
371-
// return strings.Join(parts, "/")
372-
// }
373-
374366
// fixSubdirs ensures that all subdirs are unique and makes symlinks as needed.
375367
func fixSubdirs(s Slice) {
376368
var maxSubdir, maxVersion, maxModule int
@@ -427,6 +419,8 @@ func fixSubdirs(s Slice) {
427419
}
428420
}
429421

422+
// fixFsNotify takes care of fsnotify annoying ability to appear under multiple different import paths.
423+
// github.com/fsnotify/fsnotify is the canonical package name.
430424
func fixFsNotify(s Slice) {
431425
key := func(i int) string {
432426
return fmt.Sprintf("%s:%s:%s:%s", s[i].account, s[i].project, s[i].version, s[i].group)
@@ -460,6 +454,7 @@ func fixFsNotify(s Slice) {
460454
// Otherwise omit the first line continuation for more compact representation.
461455
const largeLimit = 3
462456

457+
// String returns G{H,L}_TUPLE variables contents.
463458
func (s Slice) String() string {
464459
sort.Slice(s, func(i, j int) bool {
465460
return s[i].defaultSortKey() < s[j].defaultSortKey()
@@ -507,6 +502,7 @@ func (s Slice) String() string {
507502

508503
type Links []*Tuple
509504

505+
// Links returns a slice of tuples that require symlinking.
510506
func (s Slice) Links() Links {
511507
var res Links
512508

@@ -525,7 +521,7 @@ func (s Slice) Links() Links {
525521
return res
526522
}
527523

528-
// String generates "post-extract" target that creates required symlinks.
524+
// String returns "post-extract" target contents.
529525
func (l Links) String() string {
530526
if len(l) == 0 {
531527
return ""

0 commit comments

Comments
 (0)