How to run golang tests after automatic compile from dev_appserver - google-app-engine

I am running dev_appserver.py and so it auto builds as I save go files (I need to run this and not goapp because of log_level I need).
When there is a successful build I would like the tests for the project (goapp test) to run automatically. How can I do this?

You could use something like https://github.com/nf/watch in a separate terminal window. It'll re-run tests in parallel to dev_appserver.py.
Install: go get github.com/nf/watch
Run from your app's directory: watch goapp test

With AppEngine, I use the entr app like so:
$ find ./*.go | entr goapp test

Related

goapp test not working,getting error "GOPATH must be absolute" while it is absolute

I'm tying to write tests for my google cloud app. I read the documents and it seems the only way to run the test locally is the running the command goapp test in the test package directory. But when I run the command I get the error go: GOPATH entry is relative; must be absolute path: "".
I'm pretty sure my GOPATH is set absolutely. Here are the results when I run the command go env | grep GOPATH:
GOPATH=":/home/mohammad/go:/home/mohammad/go/src/gitlab.com/gc-auth"
Also getting the same output when I run echo $GOPATH.
Any help is appreciated.
PS: I have ubuntu 18.04 and my go version is 1.10.4
results of gcloud version:
Google Cloud SDK 228.0.0
app-engine-go
app-engine-python 1.9.80
bq 2.0.39
cloud-datastore-emulator 2.0.2
core 2018.12.07
gsutil 4.34
GOPATH=":/home/mohammad/go:/home/mohammad/go/src/gitlab.com/gc-auth"
The GOPATH starts with an empty path (which is technically relative), followed by two absolute paths. The error message is correct.

manage Jenkins build status

I'd like to run batch using jenkins. And the status of build depends of number of files created in a specific folder. My question is how could I manage Jenkins build status depending of number of files created?
You can execute a shell script to count the files and return 1, if the count isn't expected.
Another way would be to use the Text-finder Plugin searching for a pattern in the console log.
Groovy Postbuild Plugin is another alternative:
buildUnstable() - sets the build result to UNSTABLE.
If you like to use the CLI you can use the following command:
java -jar jenkins-cli.jar -s http://...:8080/ set-build-result
Sets the result of the current build. Works only if invoked from within a build.

How to visualize code coverage information on Go GAE apps?

I am developing a server with the latest Go GAE SDK. I am running tests after every change:
goapp test -test.v=true
I am using -cover to record coverage as described by goapp help testflag:
goapp test -cover -test.v=true -test.coverprofile=c.out
[..]
coverage: 53.8% of statements
ok _/var/lib/jenkins/jobs/loyalty/workspace 30.464s
This completes successfully and prints the percentage of lines covered by tests. However, attempting to visualize the results fails:
goapp tool cover -html=c.out
cover: can't find "app.go": cannot find package "_/home/ingo/git/loyalty/" in any of:
/home/ingo/Downloads/go_appengine_sdk_linux_amd64-1.9.10/go_appengine/goroot/src/pkg/_/home/ingo/git/loyalty (from $GOROOT)
/home/ingo/git/loyalty/src/_/home/ingo/git/loyalty (from $GOPATH)
Does Go's cover tool only work on non-GAE apps? Do I have to package my app differently in order to visualize the coverage results?
I unsuccessfully asked this on golang-nuts before.
There is an open issue related to it. As a temporary workaround, I am running sed in between collecting and visualizing the coverage results.
goapp test -cover -test.v=true -test.coverprofile=c.out
sed -i -e "s#.*/\(.*\.go\)#\./\\1#" c.out
goapp tool cover -html c.out -o coverage.html

Compile App Engine application in Travis

Is there any way to run the compiler on an App Engine application written in Go without continue to serve the application with the development server and instead get an exit code?
Because I want to add a check in my automated tests in Travis that the application actually compiles.
To clarify: I have access to the App Engine SDK / Development Server in Travis, but I dont want to run goapp serve since it never exits.
Without actually implementing test, your solution looks pretty hacky. Why not use goapp build? Here's my .travis.yml:
language: go
go:
- 1.2.1
# Grab newest version and suck down
install:
- export FILE=go_appengine_sdk_linux_amd64-$(curl https://appengine.google.com/api/updatecheck | grep release | grep -o '[0-9\.]*').zip
- curl -O https://storage.googleapis.com/appengine-sdks/featured/$FILE
- unzip -q $FILE
# Run build and tests
script:
- ./go_appengine/goapp test ./tests; # If you are testing
- ./go_appengine/goapp build ./packagedir; # Wherever you keep your stuff
For reference on tests or just to see a project that builds
Edit:
It has been awhile, but I noticed recently that some of my builds randomly break. It is infuriating and I have occasionally hardcoded SDK values to overcome this. No more. Here's a very hacky implementation of grabbing the first featured (and thus hosted as /updatecheck fails to always return a hosted version) of the SDK desired:
export FILE=$(curl https://storage.googleapis.com/appengine-sdks/ | grep -o 'featured/go_appengine_sdk_linux_amd64-[^\<]*' | head -1)
For just the file:
export FILE=$(curl https://storage.googleapis.com/appengine-sdks/ | grep -oP '(?<=featured/)go_appengine_sdk_linux_amd64-[^\<]*' | head -1)
I solved this by adding an empty Unit test at the entry point of the application (main_test.go). This unit test will force the whole application to compile.
Then I execute all unit tests by putting goapp test ./... in the script section.

How to download GAE logs using maven plugin?

I am using the maven gae plugin for my build and deploy of google appengine app (under windows). All works as expected.
However - I notice its also possible to download the GAE with the same pluggin. It looks to me like something like:
mvn -DoutputFile=./test.log gae:logs
should work - however it just gets stuck at:
0% Beginning to retrieve log records...
and goes no further - what am I doing wrong?
Using
mvn -e
or
mvn -X
don't seem to provide any helpful output
I tried an absolute path as well on OSX and it refuses to honor the -DoutputFile argument and puts the logs in target/gae.log no matter where I try and tell it to put it or name it instead.
So go look in your project_dir/target/gae.log file

Resources