This is an automated email from the ASF dual-hosted git repository.

shamrick 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 9c4ba13fa9 Unit test coverage for API v5 Statuses (#7710)
9c4ba13fa9 is described below

commit 9c4ba13fa9c805388eec3007a315926f4f0fed79
Author: Zach Hoffman <[email protected]>
AuthorDate: Mon Aug 14 06:59:59 2023 -0600

    Unit test coverage for API v5 Statuses (#7710)
    
    Unit test coverage
---
 .../traffic_ops_golang/status/statuses_test.go     | 82 ++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/traffic_ops/traffic_ops_golang/status/statuses_test.go 
b/traffic_ops/traffic_ops_golang/status/statuses_test.go
index c9dbfae360..16e1068258 100644
--- a/traffic_ops/traffic_ops_golang/status/statuses_test.go
+++ b/traffic_ops/traffic_ops_golang/status/statuses_test.go
@@ -24,12 +24,94 @@ import (
        "time"
 
        "github.com/apache/trafficcontrol/lib/go-tc"
+       "github.com/apache/trafficcontrol/lib/go-util"
        "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
        "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/test"
        "github.com/jmoiron/sqlx"
        sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
 )
 
+func getTestStatusesV5() []tc.StatusV5 {
+       cdns := []tc.StatusV5{}
+       testStatus := tc.StatusV5{
+               Description: util.Ptr("description"),
+               ID:          util.Ptr(1),
+               Name:        util.Ptr("cdn1"),
+               LastUpdated: util.Ptr(time.Now()),
+       }
+       cdns = append(cdns, testStatus)
+
+       testStatus2 := testStatus
+       testStatus2.Name = util.Ptr("cdn2")
+       testStatus2.Description = util.Ptr("description2")
+       cdns = append(cdns, testStatus2)
+
+       return cdns
+}
+
+func TestReadStatusesV5(t *testing.T) {
+
+       mockDB, mock, err := sqlmock.New()
+       if err != nil {
+               t.Fatalf("an error '%s' was not expected when opening a stub 
database connection", err)
+       }
+       defer mockDB.Close()
+
+       db := sqlx.NewDb(mockDB, "sqlmock")
+       defer db.Close()
+
+       testStatuses := getTestStatusesV5()
+       cols := test.ColsFromStructByTag("db", tc.StatusV5{})
+       rows := sqlmock.NewRows(cols)
+
+       for _, ts := range testStatuses {
+               rows = rows.AddRow(
+                       *ts.Description,
+                       *ts.ID,
+                       *ts.LastUpdated,
+                       *ts.Name,
+               )
+       }
+       mock.ExpectBegin()
+       mock.ExpectQuery("SELECT").WillReturnRows(rows)
+       mock.ExpectCommit()
+
+       reqInfo := api.APIInfo{Tx: db.MustBegin(), Params: 
map[string]string{"dsId": "1"}}
+
+       obj := TOStatusV5{
+               APIInfoImpl: api.APIInfoImpl{ReqInfo: &reqInfo},
+       }
+       statuses, userErr, sysErr, _, _ := obj.Read(nil, false)
+       if userErr != nil || sysErr != nil {
+               t.Errorf("Read expected: no errors, actual: %v %v", userErr, 
sysErr)
+       }
+
+       if len(statuses) != 2 {
+               t.Errorf("status.Read expected: len(statuses) == 2, actual: 
%v", len(statuses))
+       }
+}
+
+func TestInterfacesV5(t *testing.T) {
+       var i interface{}
+       i = &TOStatusV5{}
+
+       if _, ok := i.(api.Creator); !ok {
+               t.Errorf("Status must be Creator")
+       }
+       if _, ok := i.(api.Reader); !ok {
+               t.Errorf("Status must be Reader")
+       }
+       if _, ok := i.(api.Updater); !ok {
+               t.Errorf("Status must be Updater")
+       }
+       if _, ok := i.(api.Deleter); !ok {
+               t.Errorf("Status must be Deleter")
+       }
+       if _, ok := i.(api.Identifier); !ok {
+               t.Errorf("Status must be Identifier")
+       }
+}
+
 func getTestStatuses() []tc.Status {
        cdns := []tc.Status{}
        testStatus := tc.Status{

Reply via email to