-
-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V3: Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' #2182
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1bdf827
Fix to use the version of goa specified in go.mod file, when 'goa gen…
ikawaha 035a14f
Cosme
ikawaha 0f4f596
Fix to use the value obtained by 'go env GOMOD' as the file path
ikawaha 36517b7
Fix lint
ikawaha 84ab7ae
Remove unused return value
ikawaha da4ef14
Add tiny go.mod parser instead of third party package
ikawaha 21a732a
Correspond to the pattern including comments
ikawaha 64b794c
Add mod regexp tests
ikawaha ad0de63
Show goa version when go get
ikawaha f39a438
Fix invalid format
ikawaha 4380c19
Remove an unused package
ikawaha 6c1e639
Revert "Show goa version when go get"
ikawaha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestGenerator_goaPackage(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
Version int | ||
Expected string | ||
}{ | ||
{ | ||
Name: "specify v2", | ||
Version: 2, | ||
Expected: "goa.design/goa", | ||
}, | ||
{ | ||
Name: "specify v3, but go.mod file does not exist", | ||
Version: 3, | ||
Expected: "goa.design/goa/v3", | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.Name, func(t *testing.T) { | ||
pkg, err := (&Generator{ | ||
DesignVersion: c.Version, | ||
}).goaPackage() | ||
if err != nil { | ||
t.Fatalf("unexpected error, %v", err) | ||
} | ||
if pkg != c.Expected { | ||
t.Errorf("expected %v, got %v", c.Expected, pkg) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestParseGoModGoaPackage(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
Mod string | ||
Package string | ||
Expected string | ||
}{ | ||
{ | ||
Name: "simple require", | ||
Mod: "require goa.design/goa/v3 v3.0.3-0.20190704022140-85024ebc66dc", | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/[email protected]", | ||
}, | ||
{ | ||
Name: "in require block", | ||
Mod: `module calc | ||
go 1.12 | ||
require ( | ||
github.com/ikawaha/kagome v1.0.0 // indirect | ||
goa.design/goa/v3 v3.0.3-0.20190704022140-85024ebc66dc | ||
goa.design/plugins/v3 v3.0.1 | ||
) | ||
`, | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/[email protected]", | ||
}, | ||
{ | ||
Name: "not found", | ||
Mod: `module calc | ||
go 1.12 | ||
require ( | ||
github.com/ikawaha/kagome v1.0.0 // indirect | ||
goa.design/plugins/v3 v3.0.1 | ||
) | ||
`, | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/v3", | ||
}, | ||
{ | ||
Name: "with replace", | ||
Mod: `module calc | ||
go 1.12 | ||
replace goa.design/goa/v3 => ../../../goa.design/goa | ||
require ( | ||
github.com/ikawaha/kagome v1.0.0 // indirect | ||
goa.design/goa/v3 v3.0.3-0.20190704022140-85024ebc66dc | ||
goa.design/plugins/v3 v3.0.1 | ||
) | ||
`, | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/[email protected]", | ||
}, | ||
{ | ||
Name: "with comment", | ||
Mod: `module calc | ||
go 1.12 | ||
replace goa.design/goa/v3 => ../../../goa.design/goa | ||
require ( | ||
github.com/ikawaha/kagome v1.0.0 // indirect | ||
goa.design/goa/v3 v3.0.3-0.20190704022140-85024ebc66dc // indirect // comment | ||
goa.design/plugins/v3 v3.0.1 | ||
) | ||
`, | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/[email protected]", | ||
}, | ||
{ | ||
Name: "require with comment", | ||
Mod: " require goa.design/goa/v3 v3.0.3-0.20190704022140-85024ebc66dc// indirect // comment", | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/[email protected]", | ||
}, | ||
{ | ||
Name: "comment out", | ||
Mod: `module calc | ||
go 1.12 | ||
replace goa.design/goa/v3 => ../../../goa.design/goa | ||
require ( | ||
github.com/ikawaha/kagome v1.0.0 // indirect | ||
// goa.design/goa/v3 v3.0.3-0.20190704022140-85024ebc66dc | ||
goa.design/plugins/v3 v3.0.1 | ||
) | ||
`, | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/v3", | ||
}, | ||
{ | ||
Name: "without version", | ||
Mod: " goa.design/goa/v3//v3.0.3-0.20190704022140-85024ebc66dc", | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/v3", | ||
}, | ||
{ | ||
Name: "different version", | ||
Mod: "goa.design/goa/v2 v2.0.3-0.20190704022140-85024ebc66dc // comment", | ||
Package: "goa.design/goa/v3", | ||
Expected: "goa.design/goa/v3", | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.Name, func(t *testing.T) { | ||
pkg, err := parseGoModGoaPackage("goa.design/goa/v3", strings.NewReader(c.Mod)) | ||
if err != nil { | ||
t.Fatalf("unexpected error, %v", err) | ||
} | ||
if pkg != c.Expected { | ||
t.Errorf("expected %v, got %v", c.Expected, pkg) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestModPatternRegexp(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
Input string | ||
Expected []string | ||
}{ | ||
{ | ||
Name: "goa v3 release version", | ||
Input: "goa.design/goa/v3 v3.0.2", | ||
Expected: []string{"goa.design/goa/v3 v3.0.2", "goa.design/goa/v3", "v3.0.2"}, | ||
}, | ||
{ | ||
Name: "goa v3 commit number", | ||
Input: "goa.design/goa/v3 02c84c9b39d845611bfe6e8a96465d698ea374b1", | ||
Expected: []string{"goa.design/goa/v3 02c84c9b39d845611bfe6e8a96465d698ea374b1", "goa.design/goa/v3", "02c84c9b39d845611bfe6e8a96465d698ea374b1"}, | ||
}, | ||
{ | ||
Name: "goa v3 with comment", | ||
Input: "goa.design/goa/v3 v3.0.2 //comment1 //comment2 //comment3", | ||
Expected: []string{"goa.design/goa/v3 v3.0.2 //comment1 //comment2 //comment3", "goa.design/goa/v3", "v3.0.2"}, | ||
}, | ||
{ | ||
Name: "goa v3 with require and comment", | ||
Input: "require goa.design/goa/v3 v3.0.2 //comment", | ||
Expected: []string{"require goa.design/goa/v3 v3.0.2 //comment", "goa.design/goa/v3", "v3.0.2"}, | ||
}, | ||
{ | ||
Name: "goa v2", | ||
Input: "goa.design/goa/v2 v2.0.0", | ||
Expected: []string{"goa.design/goa/v2 v2.0.0", "goa.design/goa/v2", "v2.0.0"}, | ||
}, | ||
{ | ||
Name: "goa v123", | ||
Input: " goa.design/goa/v123 v123.4.5 ", | ||
Expected: []string{" goa.design/goa/v123 v123.4.5 ", "goa.design/goa/v123", "v123.4.5"}, | ||
}, | ||
{ | ||
Name: "without version", | ||
Input: "goa.design/goa/v3", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "comment out", | ||
Input: "// goa.design/goa/v3 v3.0.0", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "irrelevant package", | ||
Input: "github.com/ikawaha/kagome v1.10.0", | ||
Expected: nil, | ||
}, | ||
} | ||
for _, c := range cases { | ||
if got := reMod.FindStringSubmatch(c.Input); !reflect.DeepEqual(c.Expected, got) { | ||
t.Errorf("expected %+v, got %+v", c.Expected, got) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops