如何在测试中传递诸如用户名和密码之类的参数
我使用以下代码来初始化与AVI控制器的连接,
func TestAvi(t *testing.T) {
aviClient, err := clients.NewAviClient("<CONTROLLERNAME>", "<USERID>",
session.SetPassword("<PASSWORD"),
session.SetTenant("<TENANT>"),
session.SetInsecure)
if err != nil {
t.Error(err)
}
然后运行 go test 命令以运行代码。 我想将ControllerName,用户ID,密码和租户外部化。这样我就可以将这些作为参数将其传递给 go test test 命令。
有什么帮助吗?
I use below code to initialize connection to avi controller,
func TestAvi(t *testing.T) {
aviClient, err := clients.NewAviClient("<CONTROLLERNAME>", "<USERID>",
session.SetPassword("<PASSWORD"),
session.SetTenant("<TENANT>"),
session.SetInsecure)
if err != nil {
t.Error(err)
}
And then I run go test command to run the code.
I would like to externalize CONTROLLERNAME, USERID, PASSWORD and TENANT. So that I can pass those as arguments to go test command.
Any assistance please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不建议通过CLI Args通过它们,它们经常被记录。
一个简单且最广泛的解决方案是通过环境变量传递此类信息,您可以使用
os.getEnv()
函数。您如何设置环境变量完全取决于您,并且可能因系统而异。
例如:
I don't recommend passing those via CLI args, they are often logged.
A simple and most widely used solution is to pass such information via environment variables, which you can read using the
os.Getenv()
function.How you set the environment variables is entirely up to you and may vary from system to system.
For example: