問題在向現(xiàn)有測試文件添加另一個測試功能后,由于添加另一個測試用例后出現(xiàn)go test -v ./...多個構(gòu)建錯誤,運(yùn)行失敗。no such file or directory但是,錯誤消息似乎與更改無關(guān)。添加的測試用例可以在底部的相關(guān)代碼部分中找到。錯誤消息是:open /tmp/go-build842273301/b118/vet.cfg: no such file or directoryopen /tmp/go-build842273301/b155/vet.cfg: no such file or directory# tornadowarnung.xyz/riotwatch/riot/staticvet: in tornadowarnung.xyz/riotwatch/riot/static, can't import facts for package "encoding/json": open $WORK/b036/vet.out: no such file or directory# tornadowarnung.xyz/riotwatch/web/server/endpoint/staticvet: open $WORK/b121/vet.cfg: no such file or directoryopen /tmp/go-build842273301/b115/vet.cfg: no such file or directoryopen /tmp/go-build842273301/b001/vet.cfg: no such file or directory# tornadowarnung.xyz/riotwatch/web/servervet: open $WORK/b152/vet.cfg: no such file or directory# tornadowarnung.xyz/riotwatch/web/server/endpoint/staticvet: open $WORK/b159/vet.cfg: no such file or directory因此,一些包顯示它們的構(gòu)建失?。篎AIL tornadowarnung.xyz/riotwatch/riot/static [build failed]FAIL tornadowarnung.xyz/riotwatch/web/server [build failed]FAIL tornadowarnung.xyz/riotwatch/web/server/endpoint [build failed]FAIL tornadowarnung.xyz/riotwatch/web/server/endpoint/static [build failed]相關(guān)代碼func TestLoader_ProfileIcon(t *testing.T) { tempDir := os.TempDir() l := Loader{ profileIconPath: tempDir, } defer os.RemoveAll(tempDir) t.Run("returns expected content", func(t *testing.T) { want := bytes.NewBufferString("image data") fileName := "123456" if err := createTestFile(t, tempDir, fileName, want); err != nil { t.Fatal(err) }重現(xiàn)錯誤很困難在我安裝了 go 1.15 的 Ubuntu 機(jī)器上,只有在我再次克隆存儲庫或清理測試緩存時才會出現(xiàn)錯誤。在本地運(yùn)行 Gitlab 作業(yè)中使用的圖像golang:alpine并運(yùn)行相同的命令時,我無法每次都重現(xiàn)此錯誤。有時會發(fā)生,但大多數(shù)時候不會。我試過的我嘗試在 go 版本 1.13、1.14 和 1.15 之間切換,但每個版本都會產(chǎn)生相同的結(jié)果。切換到任何其他圖像golang:latest,如golang:1.14或golang:1.13也無濟(jì)于事。我已經(jīng)嘗試使用谷歌搜索發(fā)生的錯誤,但我沒有找到任何相關(guān)的結(jié)果或包含我尚未嘗試過的任何解決方案?;謴?fù)所述提交將使測試再次通過。我還恢復(fù)了提交并慢慢嘗試手動再次引入更改。這使得問題再次出現(xiàn)。
2 回答

慕姐8265434
TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個贊
os.TempDir 不會為您創(chuàng)建新的臨時目錄,它會返回系統(tǒng)的臨時目錄。通過在其上調(diào)用
os.RemoveAll,您將把整個事情吹走,包括構(gòu)建和測試過程使用的一些暫存文件。

撒科打諢
TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個贊
我可以驗(yàn)證 MacOS 上的行為。
好像有什么問題os.TempDir()
。
當(dāng)我自己創(chuàng)建目錄時,您的測試運(yùn)行了os.Mkdir(...)
.
您應(yīng)該在 Go 存儲庫中創(chuàng)建一個問題。
- 2 回答
- 0 關(guān)注
- 183 瀏覽
添加回答
舉報
0/150
提交
取消