You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2022/05/13 21:37:29 UTC
[trafficcontrol] branch master updated: Refactor cdn_domains, cdnnotifications, cookie, logs, ping, traffic_vault_ping tests (#6762)
This is an automated email from the ASF dual-hosted git repository.
ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 83b3dc381c Refactor cdn_domains, cdnnotifications, cookie, logs, ping, traffic_vault_ping tests (#6762)
83b3dc381c is described below
commit 83b3dc381c70572cda85b2996745ad8527e72a43
Author: Eric Holguin <14...@users.noreply.github.com>
AuthorDate: Fri May 13 15:37:24 2022 -0600
Refactor cdn_domains, cdnnotifications, cookie, logs, ping, traffic_vault_ping tests (#6762)
* Refactor cdn domains tests
* Refactor tests
* Refactor logs tests
* Refactor ping tests
* Refactor traffic vault ping test
---
traffic_ops/testing/api/v3/cdn_domains_test.go | 60 ++++++++-------
traffic_ops/testing/api/v3/logs_test.go | 61 ++++++++++-----
traffic_ops/testing/api/v3/ping_test.go | 34 ++++++--
traffic_ops/testing/api/v4/cdn_domains_test.go | 57 ++++++++------
.../testing/api/v4/cdnnotifications_test.go | 90 ++++++++++++++--------
traffic_ops/testing/api/v4/logs_test.go | 84 ++++++++++++--------
traffic_ops/testing/api/v4/ping_test.go | 33 ++++++--
.../testing/api/v4/traffic_vault_ping_test.go | 39 ++++++++--
8 files changed, 301 insertions(+), 157 deletions(-)
diff --git a/traffic_ops/testing/api/v3/cdn_domains_test.go b/traffic_ops/testing/api/v3/cdn_domains_test.go
index f83b8ad385..bd25814a46 100644
--- a/traffic_ops/testing/api/v3/cdn_domains_test.go
+++ b/traffic_ops/testing/api/v3/cdn_domains_test.go
@@ -21,34 +21,42 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-rfc"
+ "github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
)
-func GetTestDomains(t *testing.T) {
- resp, _, err := TOSession.GetDomains()
- t.Log("Response: ", resp)
- if err != nil {
- t.Errorf("could not GET domains: %v", err)
- }
-}
-
-func GetTestDomainsIMS(t *testing.T) {
- var header http.Header
- header = make(map[string][]string)
- futureTime := time.Now().AddDate(0, 0, 1)
- time := futureTime.Format(time.RFC1123)
- header.Set(rfc.IfModifiedSince, time)
- _, reqInf, err := TOSession.GetDomainsWithHdr(header)
- if err != nil {
- t.Fatalf("could not GET domains: %v", err)
- }
- if reqInf.StatusCode != http.StatusNotModified {
- t.Fatalf("Expected 304 status code, got %v", reqInf.StatusCode)
- }
-}
-
-func TestDomains(t *testing.T) {
+func TestCDNDomains(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, Statuses}, func() {
- GetTestDomains(t)
- GetTestDomainsIMS(t)
+
+ tomorrow := time.Now().AddDate(0, 0, 1).Format(time.RFC1123)
+
+ methodTests := utils.V3TestCase{
+ "GET": {
+ "NOT MODIFIED when NO CHANGES made": {
+ ClientSession: TOSession, RequestHeaders: http.Header{rfc.IfModifiedSince: {tomorrow}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+ },
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseLengthGreaterOrEqual(1)),
+ },
+ },
+ }
+
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetDomainsWithHdr(testCase.RequestHeaders)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp, tc.Alerts{}, err)
+ }
+ })
+ }
+ }
+ })
+ }
})
}
diff --git a/traffic_ops/testing/api/v3/logs_test.go b/traffic_ops/testing/api/v3/logs_test.go
index 8f4c8bb1da..c45a48baff 100644
--- a/traffic_ops/testing/api/v3/logs_test.go
+++ b/traffic_ops/testing/api/v3/logs_test.go
@@ -16,29 +16,54 @@ package v3
*/
import (
+ "net/http"
+ "net/url"
+ "strconv"
"testing"
+
+ "github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
)
func TestLogs(t *testing.T) {
WithObjs(t, []TCObj{Roles, Tenants, Users}, func() { // Objs added to create logs when this test is run alone
- GetTestLogs(t)
- GetTestLogsByLimit(t)
- })
-}
-func GetTestLogs(t *testing.T) {
- _, _, err := TOSession.GetLogs()
- if err != nil {
- t.Fatalf("error getting logs: " + err.Error())
- }
-}
+ methodTests := utils.V3TestCase{
+ "GET": {
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseLengthGreaterOrEqual(1)),
+ },
+ "RESPONSE LENGTH matches LIMIT parameter": {
+ ClientSession: TOSession, RequestParams: url.Values{"limit": {"10"}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseHasLength(10)),
+ },
+ },
+ }
-func GetTestLogsByLimit(t *testing.T) {
- toLogs, _, err := TOSession.GetLogsByLimit(10)
- if err != nil {
- t.Fatalf("error getting logs: " + err.Error())
- }
- if len(toLogs) != 10 {
- t.Fatalf("GET logs by limit: incorrect number of logs returned (%v)", len(toLogs))
- }
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ if name == "RESPONSE LENGTH matches LIMIT parameter" {
+ limit, _ := strconv.Atoi(testCase.RequestParams["limit"][0])
+ resp, reqInf, err := testCase.ClientSession.GetLogsByLimit(limit)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp, tc.Alerts{}, err)
+ }
+ } else {
+ resp, reqInf, err := testCase.ClientSession.GetLogs()
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp, tc.Alerts{}, err)
+ }
+ }
+ })
+ }
+ }
+ })
+ }
+ })
}
diff --git a/traffic_ops/testing/api/v3/ping_test.go b/traffic_ops/testing/api/v3/ping_test.go
index b2635b5daa..a43045eb71 100644
--- a/traffic_ops/testing/api/v3/ping_test.go
+++ b/traffic_ops/testing/api/v3/ping_test.go
@@ -16,17 +16,39 @@ package v3
*/
import (
+ "net/http"
"testing"
+
+ "github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
)
func TestPing(t *testing.T) {
- _, _, err := TOSession.Ping()
- if err != nil {
- t.Errorf("could not Ping authenticated: %v", err)
+
+ methodTests := utils.V3TestCase{
+ "GET": {
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when UNAUTHENTICATED": {
+ ClientSession: NoAuthTOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
}
- _, _, err = NoAuthTOSession.Ping()
- if err != nil {
- t.Errorf("could not Ping unauthenticated: %v", err)
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.Ping()
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp, tc.Alerts{}, err)
+ }
+ })
+ }
+ }
+ })
}
}
diff --git a/traffic_ops/testing/api/v4/cdn_domains_test.go b/traffic_ops/testing/api/v4/cdn_domains_test.go
index 44dc007ec0..0c0a9fccf2 100644
--- a/traffic_ops/testing/api/v4/cdn_domains_test.go
+++ b/traffic_ops/testing/api/v4/cdn_domains_test.go
@@ -21,33 +21,42 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-rfc"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
-func GetTestDomains(t *testing.T) {
- resp, _, err := TOSession.GetDomains(client.RequestOptions{})
- if err != nil {
- t.Errorf("could not GET domains: %v - alerts: %+v", err, resp.Alerts)
- }
-}
-
-func GetTestDomainsIMS(t *testing.T) {
- opts := client.NewRequestOptions()
- futureTime := time.Now().AddDate(0, 0, 1)
- time := futureTime.Format(time.RFC1123)
- opts.Header.Set(rfc.IfModifiedSince, time)
- resp, reqInf, err := TOSession.GetDomains(opts)
- if err != nil {
- t.Fatalf("could not GET domains: %v - alerts: %+v", err, resp.Alerts)
- }
- if reqInf.StatusCode != http.StatusNotModified {
- t.Fatalf("Expected 304 status code, got %v", reqInf.StatusCode)
- }
-}
-
-func TestDomains(t *testing.T) {
+func TestCDNDomains(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, Statuses}, func() {
- GetTestDomains(t)
- GetTestDomainsIMS(t)
+
+ tomorrow := time.Now().AddDate(0, 0, 1).Format(time.RFC1123)
+
+ methodTests := utils.V4TestCase{
+ "GET": {
+ "NOT MODIFIED when NO CHANGES made": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfModifiedSince: {tomorrow}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+ },
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseLengthGreaterOrEqual(1)),
+ },
+ },
+ }
+
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetDomains(testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ }
+ }
+ })
+ }
})
}
diff --git a/traffic_ops/testing/api/v4/cdnnotifications_test.go b/traffic_ops/testing/api/v4/cdnnotifications_test.go
index 2bab26dd37..9a81caea35 100644
--- a/traffic_ops/testing/api/v4/cdnnotifications_test.go
+++ b/traffic_ops/testing/api/v4/cdnnotifications_test.go
@@ -16,34 +16,61 @@ package v4
*/
import (
+ "net/http"
+ "net/url"
+ "strconv"
"testing"
"github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
+ "github.com/apache/trafficcontrol/traffic_ops/toclientlib"
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestCDNNotifications(t *testing.T) {
WithObjs(t, []TCObj{CDNs, CDNNotifications}, func() {
- GetTestCDNotifications(t)
+ methodTests := utils.V4TestCase{
+ "GET": {
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseLengthGreaterOrEqual(1)),
+ },
+ "OK when VALID CDN parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"cdn": {"cdn2"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseHasLength(1),
+ validateCDNNotificationFields(map[string]interface{}{"Notification": "test notification: cdn2"})),
+ },
+ },
+ }
+
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetCDNNotifications(testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ }
+ }
+ })
+ }
})
}
-// Note that this test will break if anyone adds a CDN notification to the test
-// data that isn't exactly `test notification: {{CDN Name}}` (where {{CDN Name}}
-// is the name of the associated CDN).
-func GetTestCDNotifications(t *testing.T) {
- opts := client.NewRequestOptions()
- for _, cdn := range testData.CDNs {
- opts.QueryParameters.Set("cdn", cdn.Name)
- resp, _, err := TOSession.GetCDNNotifications(opts)
- if err != nil {
- t.Errorf("cannot get CDN Notification for CDN '%s': %v - alerts: %+v", cdn.Name, err, resp.Alerts)
- }
- if len(resp.Response) > 0 {
- respNotification := resp.Response[0]
- expectedNotification := "test notification: " + cdn.Name
- if respNotification.Notification != expectedNotification {
- t.Errorf("expected notification does not match actual: %s, expected: %s", respNotification.Notification, expectedNotification)
+func validateCDNNotificationFields(expectedResp map[string]interface{}) utils.CkReqFunc {
+ return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
+ notifications := resp.([]tc.CDNNotification)
+ for field, expected := range expectedResp {
+ for _, notification := range notifications {
+ switch field {
+ case "Notification":
+ assert.Equal(t, expected, notification.Notification, "Expected Notification to be %v, but got %v", expected, notification.Notification)
+ }
}
}
}
@@ -53,26 +80,21 @@ func CreateTestCDNNotifications(t *testing.T) {
var opts client.RequestOptions
for _, cdn := range testData.CDNs {
resp, _, err := TOSession.CreateCDNNotification(tc.CDNNotificationRequest{CDN: cdn.Name, Notification: "test notification: " + cdn.Name}, opts)
- if err != nil {
- t.Errorf("cannot create CDN Notification for CDN '%s': %v - alerts: %+v", cdn.Name, err, resp.Alerts)
- }
+ assert.NoError(t, err, "Cannot create CDN Notification for CDN '%s': %v - alerts: %+v", cdn.Name, err, resp.Alerts)
}
}
func DeleteTestCDNNotifications(t *testing.T) {
- opts := client.NewRequestOptions()
- for _, cdn := range testData.CDNs {
- // Retrieve the notifications for a cdn
- resp, _, err := TOSession.GetCDNNotifications(opts)
- if err != nil {
- t.Errorf("cannot get notifications for CDN '%s': %v - alerts: %+v", cdn.Name, err, resp.Alerts)
- }
- if len(resp.Response) > 0 {
- respNotification := resp.Response[0]
- delResp, _, err := TOSession.DeleteCDNNotification(respNotification.ID, client.RequestOptions{})
- if err != nil {
- t.Errorf("cannot delete CDN notification #%d: %v - alerts: %+v", respNotification.ID, err, delResp.Alerts)
- }
- }
+ resp, _, err := TOSession.GetCDNNotifications(client.RequestOptions{})
+ assert.NoError(t, err, "Cannot get notifications for CDNs: %v - alerts: %+v", err, resp.Alerts)
+ for _, notification := range resp.Response {
+ delResp, _, err := TOSession.DeleteCDNNotification(notification.ID, client.RequestOptions{})
+ assert.NoError(t, err, "Cannot delete CDN notification #%d: %v - alerts: %+v", notification.ID, err, delResp.Alerts)
+ // Retrieve CDN Notification to see if it got deleted
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("id", strconv.Itoa(notification.ID))
+ getNotification, _, err := TOSession.GetCDNNotifications(opts)
+ assert.NoError(t, err, "Error deleting CDN Notification for '%s' : %v - alerts: %+v", notification.ID, err, getNotification.Alerts)
+ assert.Equal(t, 0, len(getNotification.Response), "Expected CDN Notification '%s' to be deleted", notification.ID)
}
}
diff --git a/traffic_ops/testing/api/v4/logs_test.go b/traffic_ops/testing/api/v4/logs_test.go
index 72b7a7aa1d..d72f7e2df2 100644
--- a/traffic_ops/testing/api/v4/logs_test.go
+++ b/traffic_ops/testing/api/v4/logs_test.go
@@ -16,51 +16,67 @@ package v4
*/
import (
+ "net/http"
+ "net/url"
"testing"
+ "github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
+ "github.com/apache/trafficcontrol/traffic_ops/toclientlib"
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestLogs(t *testing.T) {
WithObjs(t, []TCObj{Roles, Tenants, Users}, func() { // Objs added to create logs when this test is run alone
- GetTestLogs(t)
- GetTestLogsByLimit(t)
- GetTestLogsByUsername(t)
- })
-}
-func GetTestLogs(t *testing.T) {
- resp, _, err := TOSession.GetLogs(client.RequestOptions{})
- if err != nil {
- t.Fatalf("error getting logs: %v - alerts: %+v", err, resp.Alerts)
- }
-}
+ methodTests := utils.V4TestCase{
+ "GET": {
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseLengthGreaterOrEqual(1)),
+ },
+ "OK when VALID USERNAME parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"username": {"admin"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+ validateLogsFields(map[string]interface{}{"User": "admin"})),
+ },
+ "RESPONSE LENGTH matches LIMIT parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"limit": {"10"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseHasLength(10)),
+ },
+ },
+ }
-func GetTestLogsByLimit(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("limit", "10")
- toLogs, _, err := TOSession.GetLogs(opts)
- if err != nil {
- t.Errorf("error getting logs: %v - alerts: %+v", err, toLogs.Alerts)
- }
- if len(toLogs.Response) != 10 {
- t.Fatalf("Get logs by limit: incorrect number of logs returned (%d)", len(toLogs.Response))
- }
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetLogs(testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ }
+ }
+ })
+ }
+ })
}
-func GetTestLogsByUsername(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("username", "admin")
- toLogs, _, err := TOSession.GetLogs(opts)
- if err != nil {
- t.Errorf("error getting logs: %v - alerts: %+v", err, toLogs.Alerts)
- }
- if len(toLogs.Response) <= 0 {
- t.Fatalf("Get logs by username: incorrect number of logs returned (%d)", len(toLogs.Response))
- }
- for _, user := range toLogs.Response {
- if *user.User != TOSession.UserName {
- t.Errorf("incorrect username seen in logs, expected: `admin`, got: %v", *user.User)
+func validateLogsFields(expectedResp map[string]interface{}) utils.CkReqFunc {
+ return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
+ logs := resp.([]tc.Log)
+ for field, expected := range expectedResp {
+ for _, log := range logs {
+ switch field {
+ case "User":
+ assert.Equal(t, expected, *log.User, "Expected User to be %v, but got %v", expected, *log.User)
+ }
+ }
}
}
}
diff --git a/traffic_ops/testing/api/v4/ping_test.go b/traffic_ops/testing/api/v4/ping_test.go
index 1c6b6f4fe6..1cce12c0ff 100644
--- a/traffic_ops/testing/api/v4/ping_test.go
+++ b/traffic_ops/testing/api/v4/ping_test.go
@@ -16,19 +16,38 @@ package v4
*/
import (
+ "net/http"
"testing"
- client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
)
func TestPing(t *testing.T) {
- resp, _, err := TOSession.Ping(client.RequestOptions{})
- if err != nil {
- t.Errorf("could not ping while authenticated: %v - alerts: %+v", err, resp.Alerts)
+
+ methodTests := utils.V4TestCase{
+ "GET": {
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when UNAUTHENTICATED": {
+ ClientSession: NoAuthTOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
}
- resp, _, err = NoAuthTOSession.Ping(client.RequestOptions{})
- if err != nil {
- t.Errorf("could not ping while unauthenticated: %v - alerts: %+v", err, resp.Alerts)
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.Ping(testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Ping, resp.Alerts, err)
+ }
+ })
+ }
+ }
+ })
}
}
diff --git a/traffic_ops/testing/api/v4/traffic_vault_ping_test.go b/traffic_ops/testing/api/v4/traffic_vault_ping_test.go
index a89dea04fc..64c40263b0 100644
--- a/traffic_ops/testing/api/v4/traffic_vault_ping_test.go
+++ b/traffic_ops/testing/api/v4/traffic_vault_ping_test.go
@@ -16,18 +16,41 @@ package v4
*/
import (
+ "net/http"
"testing"
- client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
)
func TestTrafficVaultPing(t *testing.T) {
- if includeSystemTests {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers}, func() {
- _, _, err := TOSession.TrafficVaultPing(client.RequestOptions{})
- if err != nil {
- t.Errorf("could not ping Traffic Vault: %v", err)
- }
- })
+
+ if !includeSystemTests {
+ t.Skip()
}
+
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers}, func() {
+ methodTests := utils.V4TestCase{
+ "GET": {
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
+ }
+
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.TrafficVaultPing(testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp, resp.Alerts, err)
+ }
+ })
+ }
+ }
+ })
+ }
+ })
}