mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix: fix getFiles test to take in a module name (not modfile name)
This commit is contained in:
parent
6e8ca617ea
commit
5a35955659
@ -1,4 +1,4 @@
|
||||
module modowners
|
||||
module github.com/grafana/grafana/scripts/modowners
|
||||
|
||||
go 1.19
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
module github.com/grafana/grafana
|
||||
module github.com/grafana/grafana/scripts/modowners
|
||||
|
||||
go 1.19
|
||||
|
||||
|
46
scripts/modowners/modowners_generation_script.go
Normal file
46
scripts/modowners/modowners_generation_script.go
Normal file
@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
/*
|
||||
load in the modules
|
||||
for each module, call func that takes in module name and return list of files
|
||||
with list of files, call func that takes in list of files, returns presumed owner (single team name)
|
||||
modify modfile, write it back out (should be straightfwd) modfile.AddComment
|
||||
need to write it back to my filesystem as go.mod.altered, compare to go.mod, raise the PR
|
||||
|
||||
|
||||
write new output to test_go.mod so i can compare and make sure it's valid
|
||||
when i want to raise pr, copy test_go.mod and paste into go.mod
|
||||
|
||||
dont worry about if things are in the right place
|
||||
|
||||
create folder called testdata
|
||||
test files in the folder
|
||||
whatever i want to do with this func, i do it with test data - return to the test
|
||||
encourages me to write thing func so it doesnt print to stdoutput and parse from OS, rather send it io.Reader with w/e go.mod file and return either io.Writer or
|
||||
call thing()
|
||||
|
||||
best way to test things is usually to use test functions, and not the main func
|
||||
no diff b/n test func and main func
|
||||
*/
|
||||
|
||||
func getFiles(moduleName string) ([]string, error) {
|
||||
fmt.Println("I AM GET FILES")
|
||||
// get list of modules
|
||||
m, err := parseGoMod(os.DirFS("."), "go.mod")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// for each module, return a list of files that import it
|
||||
for _, mod := range m {
|
||||
if mod.Indirect == false {
|
||||
fmt.Println(mod)
|
||||
}
|
||||
}
|
||||
return []string{}, nil
|
||||
}
|
@ -5,27 +5,16 @@ import (
|
||||
)
|
||||
|
||||
/*
|
||||
load in the modules
|
||||
|
||||
for each module, call func that takes in module name and return list of files
|
||||
with list of files, call func that takes in list of files, returns presumed owner (single team name)
|
||||
modify modfile, write it back out (should be straightfwd) modfile.AddComment
|
||||
need to write it back to my filesystem as go.mod.altered, compare to go.mod, raise the PR
|
||||
|
||||
write new output to test_go.mod so i can compare and make sure it's valid
|
||||
|
||||
when i want to raise pr, copy test_go.mod and paste into go.mod
|
||||
|
||||
dont worry about if things are in the right place
|
||||
question: how do i mock files that import the below 3 imports and use said imports?
|
||||
*/
|
||||
func TestGetFiles(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
moduleName string
|
||||
expectedResult []string
|
||||
}{
|
||||
{"test1.mod", []string{"file1.go", "file2.go", "file3.go"}},
|
||||
{"test2.mod", []string{"file4.go"}},
|
||||
{"test3.mod", []string{"file5.go", "file6.go", "file7.go", "file8.go"}},
|
||||
{"cloud.google.com/go/storage v1.28.1", []string{"file1.go", "file2.go", "file3.go"}},
|
||||
{"cuelang.org/go v0.5.0", []string{"file4.go"}},
|
||||
{"github.com/Azure/azure-sdk-for-go v65.0.0+incompatible", []string{"file2.go", "file4.go", "file5.go"}},
|
||||
} {
|
||||
result, err := getFiles(test.moduleName)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user