test(cmd): add ModulePath test (#2337)

pull/2367/head
180909 2 years ago committed by GitHub
parent 8d76eebf8b
commit 18c5734930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      cmd/kratos/internal/base/mod_test.go

@ -1,6 +1,9 @@
package base
import "testing"
import (
"os"
"testing"
)
func TestModuleVersion(t *testing.T) {
v, err := ModuleVersion("golang.org/x/mod")
@ -9,3 +12,32 @@ func TestModuleVersion(t *testing.T) {
}
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)
}
}

Loading…
Cancel
Save