Skip to content

Commit

Permalink
rewrite e2e test in go
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgk committed Apr 12, 2020
1 parent aef4504 commit 1f184ad
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 28 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ all: build
build:
@go build

test: all
go test -tags=online ./...
./e2e.sh
test:
go test -tags=online,e2e ./...

install:
@go install
Expand Down
14 changes: 0 additions & 14 deletions e2e.sh

This file was deleted.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/dmgk/modules2tuple

go 1.13

require github.com/sergi/go-diff v1.1.0
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
78 changes: 78 additions & 0 deletions parser/parser_e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// +build e2e

package parser

import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"testing"

"github.com/sergi/go-diff/diffmatchpatch"
)

const testdataPath = "../testdata"

type example struct {
modules, expected string
}

func TestParserE2E(t *testing.T) {
examples, err := loadExamples()
if err != nil {
t.Fatal(err)
}

for n, x := range examples {
expected, err := ioutil.ReadFile(x.expected)
if err != nil {
t.Fatal(err)
}

actual, err := Load(x.modules)
if err != nil {
t.Fatal(err)
}

dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(strings.TrimSpace(string(expected)), strings.TrimSpace(actual.String()), false)
if dmp.DiffLevenshtein(diffs) > 0 {
t.Errorf("%s: expected output doesn't match actual:\n%s", n, dmp.DiffPrettyText(diffs))
}
}
}

func loadExamples() (map[string]*example, error) {
res := map[string]*example{}

dir, err := ioutil.ReadDir(testdataPath)
if err != nil {
return nil, err
}

for _, f := range dir {
name := f.Name()
parts := strings.SplitN(strings.TrimSuffix(name, filepath.Ext(name)), "_", 2)
if len(parts) < 2 {
return nil, fmt.Errorf("unexpected testdata file name: %q", name)
}
key, kind := parts[0], parts[1]

x, ok := res[key]
if !ok {
x = &example{}
res[key] = x
}
switch kind {
case "modules":
x.modules = filepath.Join(testdataPath, name)
case "expected":
x.expected = filepath.Join(testdataPath, name)
default:
return nil, fmt.Errorf("unexpected testdata file name: %q", name)
}
}

return res, nil
}
2 changes: 1 addition & 1 deletion parser/parser_offline_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !online
// +build !online,!e2e

package parser

Expand Down
16 changes: 6 additions & 10 deletions tuple/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type Tuple struct {
source Source // tuple source (Github ot Gitlab)
account string // source account
project string // source project
hidden bool
hidden bool // if true, tuple will be excluded from G{H,L}_TUPLE
}

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

// func reverseVersion(v string) string {
// parts := strings.Split(v, "/")
// for i, j := 0, len(parts)-1; i < j; i, j = i+1, j-1 {
// parts[i], parts[j] = parts[j], parts[i]
// }
// return strings.Join(parts, "/")
// }

// fixSubdirs ensures that all subdirs are unique and makes symlinks as needed.
func fixSubdirs(s Slice) {
var maxSubdir, maxVersion, maxModule int
Expand Down Expand Up @@ -427,6 +419,8 @@ func fixSubdirs(s Slice) {
}
}

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

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

type Links []*Tuple

// Links returns a slice of tuples that require symlinking.
func (s Slice) Links() Links {
var res Links

Expand All @@ -525,7 +521,7 @@ func (s Slice) Links() Links {
return res
}

// String generates "post-extract" target that creates required symlinks.
// String returns "post-extract" target contents.
func (l Links) String() string {
if len(l) == 0 {
return ""
Expand Down

0 comments on commit 1f184ad

Please sign in to comment.