【问题标题】:travis not find my package golangtravis 找不到我的包 golang
【发布时间】:2018-11-17 09:26:37
【问题描述】:

我的结构项目

currency-quote-api - 
                |
                |- scraping/ file.go
                |- api/ file.go
                |- tests/ test.go
                |- main.go

当我在 travis CI 中运行测试时,出现以下错误

tests/scraping_test.go:4:2: cannot find package "currency-quote-api/scraping" in any of:
/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/currency-quote-api/scraping (from $GOROOT)
/home/travis/gopath/src/github.com/matheussilva97/currency-quote-api/Godeps/_workspace/src/currency-quote-api/scraping (from $GOPATH)
/home/travis/gopath/src/currency-quote-api/scraping

我做错了什么?

我的 .travis.yml

sudo: false

language: go

go:
  -  1.10.2

notifications:
    email: false

before_script:
  - go get github.com/gorilla/mux
  - go get github.com/PuerkitoBio/goquery

script: 
  - go test -v ./tests/

【问题讨论】:

  • 您的项目源代码在GOPATH下似乎不可用。
  • 这是 Travis 独有的问题吗?你如何在你的机器上编译它?另外:您的包裹布局看起来很可疑。你确定你在这里做什么?
  • 我不能这样配置我的包?我需要将所有文件放在项目的根目录下吗?我只是运行 main.go 并工作,我在 import 中导入其他包,比如这个 import("currency-quote-api/api")
  • 阅读如何编写 Go 代码并逐字逐句地坚持下去。
  • Go(特别是 go cli 工具)非常固执己见。看起来您试图在没有真正了解您所做的方式或所做的事情的情况下偏离标准。 golang.org/doc/code.html

标签: go travis-ci


【解决方案1】:

为什么不隐式获取所有包:

before_script: - go get -t -v ./...

对于测试,由于每个测试都可以有自己的依赖项(取决于您将测试放在哪个包中),因此您应该有这样的脚本:

for d in $(go list ./... | grep -v vendor); do
  go test -race -coverprofile=profile.out -covermode=atomic $d
done

【讨论】:

    猜你喜欢
    • 2014-04-21
    • 1970-01-01
    • 2020-11-06
    • 2015-10-30
    • 2020-05-14
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2019-02-25
    相关资源
    最近更新 更多