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

srijeet0406 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 29a6832dd6 Added unit tests for cdn folder (#7476)
29a6832dd6 is described below

commit 29a6832dd633621a5211f6bb5439d6bbb4fd91ef
Author: Rima Shah <[email protected]>
AuthorDate: Fri May 5 08:45:30 2023 -0600

    Added unit tests for cdn folder (#7476)
    
    * Added two new test files in cdn folder.
    
    * Added tests
    
    * Added tests-1
---
 .../traffic_ops_golang/cdn/capacity_test.go        | 12 ++--
 .../traffic_ops_golang/cdn/dnssecrefresh_test.go   | 64 +++++++++++++++++
 traffic_ops/traffic_ops_golang/cdn/genksk_test.go  | 84 ++++++++++++++++++++++
 3 files changed, 154 insertions(+), 6 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/cdn/capacity_test.go 
b/traffic_ops/traffic_ops_golang/cdn/capacity_test.go
index 74e56f24ec..f1bcc85431 100644
--- a/traffic_ops/traffic_ops_golang/cdn/capacity_test.go
+++ b/traffic_ops/traffic_ops_golang/cdn/capacity_test.go
@@ -1,11 +1,5 @@
 package cdn
 
-import (
-       "testing"
-
-       "github.com/apache/trafficcontrol/lib/go-tc"
-)
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -25,6 +19,12 @@ import (
  * under the License.
  */
 
+import (
+       "testing"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
 func TestGetStatsFromServiceInterface(t *testing.T) {
        data1 := tc.ServerStats{
                Interfaces: nil,
diff --git a/traffic_ops/traffic_ops_golang/cdn/dnssecrefresh_test.go 
b/traffic_ops/traffic_ops_golang/cdn/dnssecrefresh_test.go
new file mode 100644
index 0000000000..9e8cc46b8e
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/cdn/dnssecrefresh_test.go
@@ -0,0 +1,64 @@
+package cdn
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+       "testing"
+
+       "github.com/jmoiron/sqlx"
+
+       "gopkg.in/DATA-DOG/go-sqlmock.v1"
+)
+
+func TestGetDNSSECKeyRefreshParams_test(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()
+
+       cols := []string{"cdn_name", "cdn_domain", "cdn_dnssec_enabled", 
"parameter_name", "parameter_value"}
+       rows := sqlmock.NewRows(cols)
+       rows.AddRow("test", "test.com", false, "", "")
+
+       mock.ExpectBegin()
+       mock.ExpectQuery("WITH cdn_profile_ids").WillReturnRows(rows)
+       mock.ExpectCommit()
+
+       params, err := getDNSSECKeyRefreshParams(db.MustBegin().Tx)
+       for _, v := range params {
+               if v.CDNName != "test" {
+                       t.Errorf("Expected cdn name: test, got: %s", v.CDNName)
+               }
+               if v.CDNDomain != "test.com" {
+                       t.Errorf("Expected cdn domain: test.com, got: %s", 
v.CDNDomain)
+               }
+               if v.DNSSECEnabled != false {
+                       t.Errorf("Expected DNSSEC to not be enabled")
+               }
+               if err != nil {
+                       t.Errorf("expected no error, got: %s", err)
+               }
+       }
+
+}
diff --git a/traffic_ops/traffic_ops_golang/cdn/genksk_test.go 
b/traffic_ops/traffic_ops_golang/cdn/genksk_test.go
new file mode 100644
index 0000000000..25e2f22604
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/cdn/genksk_test.go
@@ -0,0 +1,84 @@
+package cdn
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+       "testing"
+
+       "github.com/jmoiron/sqlx"
+
+       "gopkg.in/DATA-DOG/go-sqlmock.v1"
+)
+
+func TestGetKSKParams(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()
+
+       rows := sqlmock.NewRows([]string{"name", "value"})
+       rows.AddRow("test", "2")
+       mock.ExpectBegin()
+       mock.ExpectQuery("WITH 
cdn_profile_id").WithArgs("test").WillReturnRows(rows)
+       mock.ExpectCommit()
+
+       ttl, mult, err := getKSKParams(db.MustBegin().Tx, "test")
+       if ttl != nil {
+               t.Errorf("expected: nil, got: %v", ttl)
+       }
+       if *mult != 2 {
+               t.Errorf("expected: 2, got: %v", *mult)
+       }
+       if err != nil {
+               t.Errorf("%s", err)
+       }
+}
+
+func TestGetKSKParamsDNSKey(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()
+
+       rows1 := sqlmock.NewRows([]string{"name", "value"})
+       rows1.AddRow("tld.ttls.DNSKEY", "5")
+       mock.ExpectBegin()
+       mock.ExpectQuery("WITH 
cdn_profile_id").WithArgs("test").WillReturnRows(rows1)
+       mock.ExpectCommit()
+
+       ttl1, mult1, err1 := getKSKParams(db.MustBegin().Tx, "test")
+       if *ttl1 != 5 {
+               t.Errorf("expected: 5, got: %v", *ttl1)
+       }
+       if mult1 != nil {
+               t.Errorf("expected: nil, got: %v", mult1)
+       }
+       if err1 != nil {
+               t.Errorf("%s", err1)
+       }
+}

Reply via email to