The Traffic Ops Client API tests are used to validate the clients responses against those from the Traffic Ops API.
In order to run the tests you will need a running instance of Traffic Ops and Traffic Ops DB:
Traffic Ops Database configured port access
Traffic Ops configured port access
Running Postgres instance with a database that matches the trafficOpsDB dbname value set in traffic-ops-test.conf
For example to set up the to_test
database do the following:
$ cd trafficcontrol/traffic_ops/app $ db/admin --env=test reset
The Traffic Ops users will be created by the tool for accessing the API once the database is accessible.
To test if db/admin
ran all migrations successfully, you can run the following command from the traffic_ops/app
directory:
db/admin -env=test dbversion
The result should be something similar to:
dbversion 2021070800000000
If migrations did not run successfully, you may see:
dbversion 20181206000000 (dirty)
Make sure trafficOpsDB dbname in traffic-ops-test.conf is set to: to_test
For more info see: http://trafficcontrol.apache.org/docs/latest/development/traffic_ops.html?highlight=reset
A running Traffic Ops Golang instance pointing to the to_test
database.
$ cd trafficcontrol/traffic_ops/traffic_ops_golang $ cp ../app/conf/cdn.conf $HOME/cdn.conf $ go build && ./traffic_ops_golang -cfg $HOME/cdn.conf -dbcfg ../app/conf/test/database.conf
Verify that the passwords defined for your to_test
database match:
trafficcontrol/traffic_ops/app/conf/test/database.conf
traffic-ops-test.conf
The integration tests are run using go test
from the traffic_ops/testing/api/ directory, however, there are some flags that need to be provided in order for the tests to work.
The flags are:
Example commands to run the tests:
Test all v3 tests:
go test ./v3/... -v --cfg=../conf/traffic-ops-test.conf
Test all v4 tests:
go test ./v4/... -v --cfg=../conf/traffic-ops-test.conf
Test all v5 tests:
go test ./v5/... -v --cfg=../conf/traffic-ops-test.conf
Only Test a specific endpoint:
go test ./v4/... -run ^TestCDNs$ -v -cfg=../conf/traffic-ops-test.conf
Only Test a specific endpoint method :
go test ./v5/... -run ^TestCacheGroups$/GET -v -cfg=../conf/traffic-ops-test.conf
Get Test Coverage:
go test ./v4/... -v --cfg=../conf/traffic-ops-test.conf -coverpkg=../../v4-client/... -coverprofile=cover.out
View the cover out file in your browser:
go tool cover -html=cover.out
-v
flag is recommended to see progress.*