The Traffic Ops Client API tests are used to validate the clients responses against those from the Traffic Ops API.
The v1 tests are for regression purposes, and the v2 tests were forked from them when Traffic Ops API v2 was merged. All further feature development will only occur in v2.
In order to run the tests you will need the following:
Port access to both the Postgres port (usually 5432) that your Traffic Ops instance is using as well as the Traffic Ops configured port (usually 443 or 60443).
An instance of Postgres running with a to_test database that has empty tables.
To get your to_test database setup do the following:
$ cd trafficcontrol/traffic_ops/app
$ db/admin --env=test reset
NOTE on passwords:
Check that the passwords defined defined for your to_test database match
here: trafficcontrol/traffic_ops/app/conf/test/database.conf
and here: traffic-ops-test.conf
The Traffic Ops users will be created by the tool for accessing the API once the database is accessible.
Note that for the database to successfully set up the tables and run the migrations, you will need goose.
On your local machines(Macs), DO NOT install goose using homebrew. It will install a different version
goose. Instead, install it using the script located at
traffic_ops/install/bin/install_goose.sh.
To test if goose migrated everything correctly, you can run the following command from the traffic_ops/app
directory:
goose -env=test status "user=traffic_ops dbname=to_test sslmode=disable"
A running Traffic Ops instance running with the secure (https) and is pointing to the to_test
database by running in MOJO_MODE=test which will point to your to_test database.
To get your to_test database setup do the following:
$ export MOJO_MODE=test
$ cd trafficcontrol/traffic_ops/app
$ bin/start.pl --secure
A running Traffic Ops Golang proxy pointing to the to_test database.
$ cd trafficcontrol/traffic_ops/traffic_ops_golang$ cp ../app/conf/cdn.conf $HOME/cdn.conf
change traffic_ops_golang->port to 8443
$ go build && ./traffic_ops_golang -cfg $HOME/cdn.conf -dbcfg ../app/conf/test/database.conf
In your local development environment, if the above command fails for an error similar to
ERROR: traffic_ops_golang.go:193: 2020-04-10T10:55:53.190298-06:00: cannot open /etc/pki/tls/certs/localhost.crt for read: open /etc/pki/tls/certs/localhost.crt: no such file or directory
you might not have the right certificates at the right locations. Follow the procedure listed
here to fix it.
Running the API Tests
The integration tests are run using go test, however, there are some flags that need to be provided in order for the tests to work.
The flags are:
usage - API Test tool usage
cfg - the config file needed to run the tests
env - Environment variables that can be used to override specific config options that are specified in the config file
env_vars - Show environment variables that can be overridden
test_data - traffic control
run - Go runtime flag for executing a specific test case
Example command to run the tests:
TO_URL=https://localhost:8443 go test -v -cfg=traffic-ops-test.conf -run TestCDNs
It can take several minutes for the API tests to complete, so using the -v flag is recommended to see progress.*