|
|
@ -1,6 +1,9 @@ |
|
|
|
package base |
|
|
|
package base |
|
|
|
|
|
|
|
|
|
|
|
import "testing" |
|
|
|
import ( |
|
|
|
|
|
|
|
"os" |
|
|
|
|
|
|
|
"testing" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func TestModuleVersion(t *testing.T) { |
|
|
|
func TestModuleVersion(t *testing.T) { |
|
|
|
v, err := ModuleVersion("golang.org/x/mod") |
|
|
|
v, err := ModuleVersion("golang.org/x/mod") |
|
|
@ -9,3 +12,32 @@ func TestModuleVersion(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
t.Log(v) |
|
|
|
t.Log(v) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestModulePath(t *testing.T) { |
|
|
|
|
|
|
|
if err := os.Mkdir("/tmp/test_mod", os.ModePerm); err != nil { |
|
|
|
|
|
|
|
t.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer os.RemoveAll("/tmp/test_mod") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f, err := os.Create("/tmp/test_mod/go.mod") |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mod := `module github.com/go-kratos/kratos/v2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
go 1.16` |
|
|
|
|
|
|
|
_, err = f.WriteString(mod) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p, err := ModulePath("/tmp/test_mod/go.mod") |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if p != "github.com/go-kratos/kratos/v2" { |
|
|
|
|
|
|
|
t.Fatalf("want: %s, got: %s", "module github.com/go-kratos/kratos/v2", p) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|