我正在測試我的應用程序,為此我需要創建具有特定擴展名的臨時文件。我的目標是在臨時目錄中創建類似于此的文件example123.ac.json。為了做到這一點,我正在使用ioutil.TempDir和ioutil.TempFile。這是我正在做的一個人為的小例子。主要去:package mainfunc main() {}main_test.go:package mainimport ( "fmt" "io/ioutil" "os" "testing")func TestMain(t *testing.T) { dir, err := ioutil.TempDir("", "testing") if err != nil { t.Fatalf("unable to create temp directory for testing") } defer os.RemoveAll(dir) file, err := ioutil.TempFile(dir, "*.ac.json") // Create a temporary file with '.ac.json' extension if err != nil { t.Fatalf("unable to create temporary file for testing") } fmt.Printf("created the following file: %v\n", file.Name())}當我在我的 Mac 上本地運行測試時,從isgo test輸出以下內容fmt.Printf$ go testcreated the following file: /var/folders/tj/1_mxwn350_d2c5r9b_2zgy7m0000gn/T/testing566832606/900756901.ac.jsonPASSok github.com/JonathonGore/travisci-bug 0.004s所以它按預期工作但是當我在 TravisCI 中運行它時,Printf 語句輸出以下內容:created the following file: /tmp/testing768620677/*.ac.json193187872出于某種原因,它在 TravisCI 中使用文字星號,但在我自己的計算機上運行時卻沒有。如果有興趣,這里是 TravisCI 日志的鏈接。為了完整起見,這是我的.travis.yml:language: gogo: - "1.10"任何人都知道這里發生了什么?還是我錯過了一些明顯的東西?
- 0 回答
- 0 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消