Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use or fix problem when I test unit-testing below trpc-go #185

Closed
2 tasks done
wuye251 opened this issue Jul 1, 2024 · 1 comment
Closed
2 tasks done

How to use or fix problem when I test unit-testing below trpc-go #185

wuye251 opened this issue Jul 1, 2024 · 1 comment
Labels
question Further information is requested

Comments

@wuye251
Copy link

wuye251 commented Jul 1, 2024

Preliminary Research

  • I have read the project's documentation.
  • I have searched existing issues for similar questions to see if my question has already been addressed.

Question

Additional Information

My unit-testing code

package service

import (
	"context"
	"flag"
	"testing"

	pb "code.teamsun.com/global_pb/intelligent_assistance.git/intelligent_assistance"
	"teamsun.com/intelligent_assistance/intelligent_assistance/internal/config"
	"teamsun.com/intelligent_assistance/intelligent_assistance/internal/dao"
	"teamsun.com/intelligent_assistance/intelligent_assistance/internal/model"
	"trpc.group/trpc-go/trpc-go"

	_ "trpc.group/trpc-go/trpc-filter/debuglog"
	_ "trpc.group/trpc-go/trpc-filter/recovery"
)

func init() {
	flag.String("config", "../../config/trpc_go.yaml", "")
	flag.String("test.run", "", "")
	s := trpc.NewServer()
	config.InitServerConfig()
	dao.New()
	pb.RegisterIntelligentAssistanceService(s.Service("intelligent_assistance.trpc"),
		&IntelligentAssistanceImpl{})
	go s.Serve()

	print("init server config success")
}

func TestEndCall(t *testing.T) {
	endCall(context.Background(), "1009", &model.CallInfo{
		Staff:        "staff",
		EnterpriseId: "1658884c2f644cdfbb647cfdb1689041",
	})
}

got:

init server config success/root/code/intelligent_assistance/internal/service/__debug_bin1147665774 flag redefined: test.run
panic: /root/code/intelligent_assistance/internal/service/__debug_bin1147665774 flag redefined: test.run

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0001d8310, {0x29f67f8, 0xc000134aa0}, {0x281aff5, 0x8}, {0x2858598, 0x2d})
	/usr/local/go/src/flag/flag.go:1028 +0x5aa
flag.(*FlagSet).StringVar(0xc0001d8310, 0xc000134aa0, {0x281aff5, 0x8}, {0x0, 0x0}, {0x2858598, 0x2d})
	/usr/local/go/src/flag/flag.go:879 +0x8e
flag.(*FlagSet).String(0xc0001d8310, {0x281aff5, 0x8}, {0x0, 0x0}, {0x2858598, 0x2d})
	/usr/local/go/src/flag/flag.go:892 +0x8f
flag.String({0x281aff5, 0x8}, {0x0, 0x0}, {0x2858598, 0x2d})
	/usr/local/go/src/flag/flag.go:899 +0x65
testing.Init()
	/usr/local/go/src/testing/testing.go:428 +0x28b

When I delete extra code. Like this:

func init() {
	trpc.NewServer()
	config.InitServerConfig()
	dao.New()

	print("init server config success")
}

got:

2024/07/01 16:23:10 maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined
flag provided but not defined: -test.run
Usage of /root/code/intelligent_assistance/internal/service/__debug_bin862289461:
  -conf string
    	server config path (default "./trpc_go.yaml")

Or how to use unit tests below trpc-go?
Thank you in advance for your help

@wuye251 wuye251 added the question Further information is requested label Jul 1, 2024
@WineChord
Copy link
Contributor

You may refer to the project's own testcase:

func TestNewServer(t *testing.T) {

@wuye251 wuye251 closed this as completed Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants