Compare commits
12 Commits
dependabot
...
main
Author | SHA1 | Date |
---|---|---|
LinXiaoWei | bffc1a0989 | 1 year ago |
包子 | 32b1d13f90 | 1 year ago |
dependabot[bot] | db2a565d1c | 1 year ago |
jessetang | fcd3b18e83 | 1 year ago |
freezeChen | 3445f3ea8e | 1 year ago |
Tony Chen | 32c0d2dd97 | 1 year ago |
xu0o0 | e86ad248c3 | 1 year ago |
liaochuntao | 69d73225a9 | 1 year ago |
Fengbin Shi | 49ffd95a0c | 1 year ago |
haiyux | 96480c11ee | 2 years ago |
dependabot[bot] | 1d50f50262 | 2 years ago |
dependabot[bot] | 6d741828c2 | 2 years ago |
@ -0,0 +1,144 @@ |
||||
package project |
||||
|
||||
import ( |
||||
"fmt" |
||||
"go/parser" |
||||
"go/token" |
||||
"os" |
||||
"path/filepath" |
||||
"testing" |
||||
|
||||
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base" |
||||
) |
||||
|
||||
// TestCmdNew tests the `kratos new` command.
|
||||
func TestCmdNew(t *testing.T) { |
||||
cwd := changeCurrentDir(t) |
||||
projectName := "helloworld" |
||||
|
||||
// create a new project
|
||||
CmdNew.SetArgs([]string{projectName}) |
||||
if err := CmdNew.Execute(); err != nil { |
||||
t.Fatalf("executing command: %v", err) |
||||
} |
||||
|
||||
// check that the expected files were created
|
||||
for _, file := range []string{ |
||||
"go.mod", |
||||
"go.sum", |
||||
"README.md", |
||||
"cmd/helloworld/main.go", |
||||
} { |
||||
if _, err := os.Stat(filepath.Join(cwd, projectName, file)); err != nil { |
||||
t.Errorf("expected file %s to exist", file) |
||||
} |
||||
} |
||||
|
||||
// check that the go.mod file contains the expected module name
|
||||
assertGoMod(t, filepath.Join(cwd, projectName, "go.mod"), projectName) |
||||
|
||||
assertImportsInclude(t, filepath.Join(cwd, projectName, "cmd", projectName, "wire.go"), fmt.Sprintf(`"%s/internal/biz"`, projectName)) |
||||
} |
||||
|
||||
// TestCmdNewNoMod tests the `kratos new` command with the --nomod flag.
|
||||
func TestCmdNewNoMod(t *testing.T) { |
||||
cwd := changeCurrentDir(t) |
||||
|
||||
// create a new project
|
||||
CmdNew.SetArgs([]string{"project"}) |
||||
if err := CmdNew.Execute(); err != nil { |
||||
t.Fatalf("executing command: %v", err) |
||||
} |
||||
|
||||
// add new app with --nomod flag
|
||||
CmdNew.SetArgs([]string{"--nomod", "project/app/user"}) |
||||
if err := CmdNew.Execute(); err != nil { |
||||
t.Fatalf("executing command: %v", err) |
||||
} |
||||
|
||||
// check that the expected files were created
|
||||
for _, file := range []string{ |
||||
"go.mod", |
||||
"go.sum", |
||||
"README.md", |
||||
"cmd/project/main.go", |
||||
"app/user/cmd/user/main.go", |
||||
} { |
||||
if _, err := os.Stat(filepath.Join(cwd, "project", file)); err != nil { |
||||
t.Errorf("expected file %s to exist", file) |
||||
} |
||||
} |
||||
|
||||
assertImportsInclude(t, filepath.Join(cwd, "project/app/user/cmd/user/wire.go"), `"project/app/user/internal/biz"`) |
||||
} |
||||
|
||||
// assertImportsInclude checks that the file at path contains the expected import.
|
||||
func assertImportsInclude(t *testing.T, path, expected string) { |
||||
t.Helper() |
||||
|
||||
got, err := imports(path) |
||||
if err != nil { |
||||
t.Fatalf("getting imports: %v", err) |
||||
} |
||||
|
||||
for _, imp := range got { |
||||
if imp == expected { |
||||
return |
||||
} |
||||
} |
||||
|
||||
t.Errorf("expected imports to include %s, got %v", expected, got) |
||||
} |
||||
|
||||
// imports returns the imports in the file at path.
|
||||
func imports(path string) ([]string, error) { |
||||
fset := token.NewFileSet() |
||||
f, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
imports := make([]string, 0, len(f.Imports)) |
||||
for _, s := range f.Imports { |
||||
imports = append(imports, s.Path.Value) |
||||
} |
||||
|
||||
return imports, nil |
||||
} |
||||
|
||||
// assertGoMod checks that the go.mod file contains the expected module name.
|
||||
func assertGoMod(t *testing.T, path, expected string) { |
||||
t.Helper() |
||||
|
||||
got, err := base.ModulePath(path) |
||||
if err != nil { |
||||
t.Fatalf("getting module path: %v", err) |
||||
} |
||||
|
||||
if got != expected { |
||||
t.Errorf("expected module name %s, got %s", expected, got) |
||||
} |
||||
} |
||||
|
||||
// change the working directory to the tempdir
|
||||
func changeCurrentDir(t *testing.T) string { |
||||
t.Helper() |
||||
|
||||
tmp := t.TempDir() |
||||
|
||||
oldCWD, err := os.Getwd() |
||||
if err != nil { |
||||
t.Fatalf("getting working directory: %v", err) |
||||
} |
||||
|
||||
if err := os.Chdir(tmp); err != nil { |
||||
t.Fatalf("changing working directory: %v", err) |
||||
} |
||||
t.Cleanup(func() { |
||||
if err := os.Chdir(oldCWD); err != nil { |
||||
t.Fatalf("restoring working directory: %v", err) |
||||
} |
||||
}) |
||||
|
||||
return tmp |
||||
} |
@ -1,4 +1,4 @@ |
||||
package main |
||||
|
||||
// release is the current kratos tool version.
|
||||
const release = "v2.6.2" |
||||
const release = "v2.6.3" |
||||
|
@ -1,4 +1,4 @@ |
||||
package main |
||||
|
||||
// release is the current protoc-gen-go-errors version.
|
||||
const release = "v2.6.2" |
||||
const release = "v2.6.3" |
||||
|
@ -1,4 +1,4 @@ |
||||
package main |
||||
|
||||
// release is the current protoc-gen-go-http version.
|
||||
const release = "v2.6.2" |
||||
const release = "v2.6.3" |
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,37 +1,45 @@ |
||||
module github.com/go-kratos/kratos/v2 |
||||
|
||||
go 1.18 |
||||
go 1.19 |
||||
|
||||
require ( |
||||
github.com/fsnotify/fsnotify v1.5.4 |
||||
github.com/fsnotify/fsnotify v1.6.0 |
||||
github.com/go-kratos/aegis v0.2.0 |
||||
github.com/go-playground/form/v4 v4.2.0 |
||||
github.com/golang-jwt/jwt/v4 v4.4.1 |
||||
github.com/google/uuid v1.3.0 |
||||
github.com/gorilla/mux v1.8.0 |
||||
github.com/imdario/mergo v0.3.12 |
||||
go.opentelemetry.io/otel v1.7.0 |
||||
go.opentelemetry.io/otel/sdk v1.7.0 |
||||
go.opentelemetry.io/otel/trace v1.7.0 |
||||
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 |
||||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd |
||||
google.golang.org/grpc v1.46.2 |
||||
google.golang.org/protobuf v1.28.0 |
||||
github.com/imdario/mergo v0.3.13 |
||||
go.opentelemetry.io/otel v1.16.0 |
||||
go.opentelemetry.io/otel/sdk v1.16.0 |
||||
go.opentelemetry.io/otel/trace v1.16.0 |
||||
golang.org/x/sync v0.2.0 |
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc |
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc |
||||
google.golang.org/grpc v1.56.1 |
||||
google.golang.org/protobuf v1.31.0 |
||||
gopkg.in/yaml.v3 v3.0.1 |
||||
) |
||||
|
||||
require ( |
||||
github.com/go-logr/logr v1.2.3 // indirect |
||||
github.com/envoyproxy/go-control-plane v0.11.2-0.20230627204322-7d0032219fcb // indirect |
||||
github.com/go-logr/logr v1.2.4 // indirect |
||||
github.com/go-logr/stdr v1.2.2 // indirect |
||||
github.com/go-ole/go-ole v1.2.6 // indirect |
||||
github.com/golang/protobuf v1.5.2 // indirect |
||||
github.com/golang/protobuf v1.5.3 // indirect |
||||
github.com/kr/pretty v0.3.1 // indirect |
||||
github.com/lufia/plan9stats v0.0.0-20230110061619-bbe2e5e100de // indirect |
||||
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect |
||||
github.com/rogpeppe/go-internal v1.10.0 // indirect |
||||
github.com/shirou/gopsutil/v3 v3.23.2 // indirect |
||||
github.com/stretchr/testify v1.8.4 // indirect |
||||
github.com/tklauser/go-sysconf v0.3.11 // indirect |
||||
github.com/tklauser/numcpus v0.6.0 // indirect |
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect |
||||
golang.org/x/net v0.7.0 // indirect |
||||
golang.org/x/sys v0.6.0 // indirect |
||||
golang.org/x/text v0.7.0 // indirect |
||||
go.opentelemetry.io/otel/metric v1.16.0 // indirect |
||||
golang.org/x/net v0.10.0 // indirect |
||||
golang.org/x/sys v0.8.0 // indirect |
||||
golang.org/x/text v0.9.0 // indirect |
||||
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect |
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect |
||||
) |
||||
|
@ -1,4 +1,4 @@ |
||||
package kratos |
||||
|
||||
// Release is the current kratos version.
|
||||
const Release = "v2.6.2" |
||||
const Release = "v2.6.3" |
||||
|
Loading…
Reference in new issue