dongyun3335 2015-04-22 00:46
浏览 43
已采纳

在以golang编写的Google App Engine应用程序中使用和测试本地包的好方法吗?

I have a problem of testing my GAE golang app uses local packages. The probject looks something like this.

.
├── app.yaml
├── main.go
└── handler
    └── handler.go

handler package is imported in main.go.

package main

import "handler"

Everything (e.g., goapp serve) works fine until I started writing tests. goapp test complains that handler package is not found. Seems like GOPATH of goapp serve and goapp test are different. One solution I found is to put handler package outside of the project path and import it with fully qualified name (e.g., github.com/.../handler) but it doesn't make sense to me to split the project in to separate places where they're tightly coupled. Are there any good way to use and test local packages?

Following resources are found on this topic.

  • 写回答

2条回答 默认 最新

  • donglang2010 2015-11-03 15:18
    关注

    This comes late, but if anyone runs into the same issue, here is how to deal with it:

    1. Organize your code this way

      /whereever
      └── /myproject
          └──/src
             ├── app.yaml
             ├── main.go
             └── /handler
                 └── handler.go
      
    2. Use unqualified imports for your project code e.g.

      import handler
      
    3. Run goapp serve and goapp deploy from inside the src folder. serve/deploy work relative to the app.yaml

      cd /whereever/myproject/src
      goapp serve 
      
    4. Set GOPATH for goapp test , it work based on GOPATH

      cd /whereever/myproject    #GOPATH expects a subfolder called src
      GOPATH=$GOPATH:`pwd`       #add the current folder to the GOPATH
      goapp test ./...           #run all tests in any subfolders
      
    5. Reset your GOPATH if necessary

      source ~/.profile #this assumes ~/.profile is where you have permanently set your GOPATH
      

    All in all, "working as intended", but still a pain.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码