-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add go mod graph and improve go list all * Add go mod graph and improve go list all * Add go mod graph and improve go list all
- Loading branch information
1 parent
42e6988
commit e10fec1
Showing
6 changed files
with
115 additions
and
81 deletions.
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 |
---|---|---|
|
@@ -12,40 +12,27 @@ import ( | |
"testing" | ||
) | ||
|
||
func TestOutputToMap(t *testing.T) { | ||
content := `go: finding github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db | ||
go: finding github.com/nwaples/rardecode v0.0.0-20171029023500-e06696f847ae | ||
go: finding github.com/pierrec/lz4 v2.0.5+incompatible | ||
go: finding github.com/ulikunitz/xz v0.5.4 | ||
go: finding github.com/dsnet/compress v0.0.0-20171208185109-cc9eb1d7ad76 | ||
go: finding github.com/mholt/archiver v2.1.0+incompatible | ||
go: finding rsc.io/quote v1.5.2 | ||
go: finding golang.org/x/tools v0.0.0-20181006002542-f60d9635b16a | ||
go: finding golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 | ||
go: finding rsc.io/sampler v1.3.0 | ||
github.com/you/hello | ||
github.com/dsnet/compress v0.0.0-20171208185109-cc9eb1d7ad76 | ||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db | ||
github.com/mholt/archiver v2.1.0+incompatible | ||
github.com/nwaples/rardecode v0.0.0-20171029023500-e06696f847ae | ||
github.com/pierrec/lz4 v2.0.5+incompatible | ||
github.com/ulikunitz/xz v0.5.4 | ||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c => golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 | ||
golang.org/x/tools v0.0.0-20181006002542-f60d9635b16a => /temp/tools | ||
rsc.io/quote v1.5.2 | ||
rsc.io/sampler v1.3.0 | ||
func TestListToMap(t *testing.T) { | ||
content := `github.com/you/hello | ||
github.com/dsnet/[email protected] | ||
github.com/golang/[email protected] | ||
github.com/mholt/[email protected]+incompatible | ||
github.com/nwaples/[email protected] | ||
github.com/pierrec/[email protected]+incompatible | ||
github.com/ulikunitz/[email protected] | ||
rsc.io/[email protected] | ||
rsc.io/[email protected] | ||
` | ||
|
||
log.SetLogger(log.NewLogger(log.ERROR, nil)) | ||
actual := outputToMap(content) | ||
actual := listToMap(content) | ||
expected := map[string]bool{ | ||
"github.com/dsnet/[email protected]": true, | ||
"github.com/golang/[email protected]": true, | ||
"github.com/mholt/[email protected]+incompatible": true, | ||
"github.com/nwaples/[email protected]": true, | ||
"github.com/pierrec/[email protected]+incompatible": true, | ||
"github.com/ulikunitz/[email protected]": true, | ||
"golang.org/x/[email protected]": true, | ||
"rsc.io/[email protected]": true, | ||
"rsc.io/[email protected]": true, | ||
} | ||
|
@@ -140,7 +127,12 @@ func TestGetDependenciesList(t *testing.T) { | |
assert.NoError(t, err) | ||
}() | ||
originSumFileContent, _, err := GetGoSum(gomodPath) | ||
|
||
err = fileutils.MoveFile(filepath.Join(gomodPath, "test.go.txt"), filepath.Join(gomodPath, "test.go")) | ||
assert.NoError(t, err) | ||
defer func() { | ||
err := fileutils.MoveFile(filepath.Join(gomodPath, "test.go"), filepath.Join(gomodPath, "test.go.txt")) | ||
assert.NoError(t, err) | ||
}() | ||
actual, err := GetDependenciesList(filepath.Join(gomodPath)) | ||
if err != nil { | ||
t.Error(err) | ||
|
@@ -154,10 +146,10 @@ func TestGetDependenciesList(t *testing.T) { | |
} | ||
|
||
expected := map[string]bool{ | ||
"golang.org/x/[email protected]": true, | ||
"golang.org/x/[email protected]": true, | ||
"rsc.io/quote@v1.5.2": true, | ||
"rsc.io/[email protected]": true, | ||
"golang.org/x/[email protected]": true, | ||
"rsc.io/[email protected]": true, | ||
"rsc.io/sampler@v1.3.0": true, | ||
"testGoList@": true, | ||
} | ||
if !reflect.DeepEqual(expected, actual) { | ||
t.Errorf("Expecting: \n%v \nGot: \n%v", expected, actual) | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module example.com/hello | ||
module testGoList | ||
|
||
go 1.16 | ||
|
||
require rsc.io/quote v1.5.2 | ||
require golang.org/x/text v0.3.3 | ||
|
||
require golang.org/x/text v0.3.3 // indirect |
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
rsc.io/quote v1.5.2 h1:w5fcysjrx7yqtD/aO+QwRjYZOKnaM9Uh2b40tElTs3Y= | ||
rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= | ||
rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4= | ||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= |
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,10 @@ | ||
package testGoList | ||
|
||
import ( | ||
"fmt" | ||
"rsc.io/quote" | ||
) | ||
|
||
func PrintHello() { | ||
fmt.Println(quote.Hello()) | ||
} |
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 |
---|---|---|
|
@@ -104,33 +104,31 @@ func GetFileDetails(filePath string) (modFileContent []byte, modFileStat os.File | |
return | ||
} | ||
|
||
func outputToMap(output string) map[string]bool { | ||
func listToMap(output string) map[string]bool { | ||
lineOutput := strings.Split(output, "\n") | ||
mapOfDeps := map[string]bool{} | ||
|
||
for _, line := range lineOutput { | ||
splitLine := strings.Split(line, " ") | ||
lineLen := len(splitLine) | ||
if lineLen == 2 { | ||
mapOfDeps[splitLine[0]+"@"+splitLine[1]] = true | ||
// The expected syntax : github.com/[email protected] | ||
if len(strings.Split(line, "@")) == 2 && mapOfDeps[line] == false { | ||
mapOfDeps[line] = true | ||
continue | ||
} | ||
// In a case of a replace statement : source version => target version | ||
// choose the target version. | ||
if lineLen == 5 { | ||
if splitLine[2] == "=>" { | ||
mapOfDeps[splitLine[3]+"@"+splitLine[4]] = true | ||
continue | ||
} | ||
} | ||
// In a case of a replace statement with a local filesystem target: source version => local_target | ||
// local target won't be added to the dependencies map. | ||
if lineLen == 4 && splitLine[0] != "go:" { | ||
if splitLine[2] == "=>" { | ||
log.Info("The replacer is not pointing to a VCS version: " + splitLine[0] + ",\nThis dependency won't be added to the requested build dependencies list.") | ||
} | ||
} | ||
} | ||
return mapOfDeps | ||
} | ||
|
||
func graphToMap(output string) map[string][]string { | ||
lineOutput := strings.Split(output, "\n") | ||
mapOfDeps := map[string][]string{} | ||
for _, line := range lineOutput { | ||
// The expected syntax : github.com/[email protected] github.com/[email protected] | ||
line = strings.ReplaceAll(line, "@v", ":") | ||
splitLine := strings.Split(line, " ") | ||
if len(splitLine) == 2 { | ||
parent := splitLine[0] | ||
child := splitLine[1] | ||
mapOfDeps[parent] = append(mapOfDeps[parent], child) | ||
} | ||
} | ||
return mapOfDeps | ||
} | ||
|