亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用銀杏故障測試兩個字符串

用銀杏故障測試兩個字符串

Go
牛魔王的故事 2021-08-16 15:49:17
首先,我想告訴你,我對 Go 非常陌生,而且我來自 Python。話雖如此,我可以繼續解決我的問題。我遇到以下問題:cacciald@cacciald-Lenovo-G470:~/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor$ go testRunning Suite: Executor Suite=============================Random Seed: 1409854483Will run 1 of 1 specs? Failure [0.005 seconds]Executor/home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:21  Should execute a command [It]  /home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:20  Expected      <string>: Hello World  to be equivalent to      <string>: Hello World  /home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:19------------------------------Summarizing 1 Failure:[Fail] Executor [It] Should execute a command /home/cacciald/workspace/gopath/src/github.com/lcacciagioni/bosh_web_console/executor/executor_test.go:19Ran 1 of 1 Specs in 0.006 secondsFAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestExecutor (0.01 seconds)FAILexit status 1FAIL    github.com/lcacciagioni/bosh_web_console/executor       0.019s這是代碼:// Package executor will provide a way to execute console commands in our// Operative System.-package executorimport (        "bytes"        "log"        "os/exec")func Runner(command, params string) string {        cmd := exec.Command(command, params)        var out bytes.Buffer        cmd.Stdout = &out        err := cmd.Run()        if err != nil {                log.Fatal(err)        }        return out.String()}這是我的簡單測試:package executor_testimport (        . "github.com/lcacciagioni/bosh_web_console/executor"        . "github.com/onsi/ginkgo"        . "github.com/onsi/gomega")var _ = Describe("Executor", func() {        var (                cmd    string                params string        )如果有人能告訴我為什么這不起作用,那就太好了?。。?
查看完整描述

1 回答

?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

你忘了\n的echo。


這工作正常:


 var _ = Describe("Executor", func() {

             var (

                     cmd    string

                     params string

             )


             It("Should execute a command", func() {

                     cmd = "echo"

                     params = "Hello World"

                     Expect(Runner(cmd, params)).To(BeEquivalentTo(params + "\n"))

             })

     })


查看完整回答
反對 回復 2021-08-16
  • 1 回答
  • 0 關注
  • 197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號