api/

directory
v8.0.0-rc0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more

README

Traffic Ops Client / API Integration Tests

The Traffic Ops Client API tests are used to validate the clients responses against those from the Traffic Ops API.

Setup

In order to run the tests you will need a running instance of Traffic Ops and Traffic Ops DB:

  1. Traffic Ops Database configured port access

    • Usually 5432 - should match the value set in database.conf and the trafficOpsDB port in traffic-ops-test.conf
  2. Traffic Ops configured port access

    • Usually 443 or 60443 - should match the value set in cdn.conf and the URL in traffic-ops-test.conf
  3. 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

  4. 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

Running the API Tests

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:

  • cfg - The config file path (default traffic-ops-test.conf)
  • fixtures - The test fixtures for the API test tool (default "tc-fixtures.json)
  • includeSystemTests - Whether to enable tests that have environment dependencies beyond a database
  • run - Go runtime flag for executing a specific test case

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
  • go test -run flag matches a regexp so if you want to ensure that only a test named TestCDNs is run use ^TestCDNs$
  • It can take several minutes for the API tests to complete, so using the -v flag is recommended to see progress.*

Directories

Path Synopsis
Package config provides tools to load and validate configuration data for Traffic Ops API tests.
Package config provides tools to load and validate configuration data for Traffic Ops API tests.
Package utils provides helpful utilities for easing the process of testing Traffic Ops API clients.
Package utils provides helpful utilities for easing the process of testing Traffic Ops API clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL