You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/05/03 14:12:19 UTC
[incubator-trafficcontrol] 03/03: Fix TO Go CRConfig unit tests
This is an automated email from the ASF dual-hosted git repository.
mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
commit 8c5e2e77d7f6794c5c35f22b2cf2e533cc61588f
Author: Robert Butts <ro...@apache.org>
AuthorDate: Wed May 2 16:14:01 2018 -0600
Fix TO Go CRConfig unit tests
---
.../traffic_ops_golang/crconfig/config_test.go | 29 ++++++++++++++--------
.../crconfig/deliveryservice_test.go | 6 +++--
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/crconfig/config_test.go b/traffic_ops/traffic_ops_golang/crconfig/config_test.go
index 86f209e..d8e135d 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/config_test.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/config_test.go
@@ -27,16 +27,19 @@ import (
"gopkg.in/DATA-DOG/go-sqlmock.v1"
)
-func ExpectedGetConfigParams() map[string]string {
- return map[string]string{
- "tld.ttls.foo" + *randStr(): *randStr(),
- "tld.soa.bar" + *randStr(): *randStr(),
+func ExpectedGetConfigParams(domain string) []CRConfigConfigParameter{
+ return []CRConfigConfigParameter{
+ {"tld.ttls.foo" + *randStr(), *randStr()},
+ {"tld.soa.bar" + *randStr(), *randStr()},
+ {"domain_name", domain},
}
}
-func MockGetConfigParams(mock sqlmock.Sqlmock, expected map[string]string, cdn string) {
+func MockGetConfigParams(mock sqlmock.Sqlmock, expected []CRConfigConfigParameter, cdn string) {
rows := sqlmock.NewRows([]string{"name", "value"})
- for n, v := range expected {
+ for _, param := range expected {
+ n := param.Name
+ v := param.Value
rows = rows.AddRow(n, v)
}
mock.ExpectQuery("select").WithArgs(cdn).WillReturnRows(rows)
@@ -50,8 +53,9 @@ func TestGetConfigParams(t *testing.T) {
defer db.Close()
cdn := "mycdn"
+ domain := "mycdn.invalid"
- expected := ExpectedGetConfigParams()
+ expected := ExpectedGetConfigParams(domain)
MockGetConfigParams(mock, expected, cdn)
actual, err := getConfigParams(cdn, db)
@@ -67,11 +71,13 @@ func TestGetConfigParams(t *testing.T) {
const soaPrefix = "tld.soa."
const ttlPrefix = "tld.ttls."
-func ExpectedMakeCRConfigConfig(expectedGetConfigParams map[string]string, expectedDNSSECEnabled bool) map[string]interface{} {
+func ExpectedMakeCRConfigConfig(expectedGetConfigParams []CRConfigConfigParameter, expectedDNSSECEnabled bool) map[string]interface{} {
m := map[string]interface{}{}
soa := map[string]string{}
ttl := map[string]string{}
- for n, v := range expectedGetConfigParams {
+ for _, param := range expectedGetConfigParams {
+ n := param.Name
+ v := param.Value
if strings.HasPrefix(n, soaPrefix) {
soa[n[len(soaPrefix):]] = v
} else if strings.HasPrefix(n, ttlPrefix) {
@@ -98,14 +104,15 @@ func TestMakeCRConfigConfig(t *testing.T) {
defer db.Close()
cdn := "mycdn"
+ domain := "mycdn.invalid"
dnssecEnabled := true
- expectedGetConfigParams := ExpectedGetConfigParams()
+ expectedGetConfigParams := ExpectedGetConfigParams(domain)
MockGetConfigParams(mock, expectedGetConfigParams, cdn)
expected := ExpectedMakeCRConfigConfig(expectedGetConfigParams, dnssecEnabled)
- actual, err := makeCRConfigConfig(cdn, db, dnssecEnabled)
+ actual, err := makeCRConfigConfig(cdn, db, dnssecEnabled, domain)
if err != nil {
t.Fatalf("makeCRConfigConfig err expected: nil, actual: %v", err)
diff --git a/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
index fe066b4..b5795e2 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
@@ -169,6 +169,7 @@ func TestMakeDSes(t *testing.T) {
defer db.Close()
cdn := "mycdn"
+ domain := "mycdn.invalid"
expected := ExpectedMakeDSes()
MockMakeDSes(mock, expected, cdn)
@@ -186,7 +187,7 @@ func TestMakeDSes(t *testing.T) {
expectedStaticDNSEntries := ExpectedGetStaticDNSEntries(expected)
MockGetStaticDNSEntries(mock, expectedStaticDNSEntries, cdn)
- actual, err := makeDSes(cdn, db)
+ actual, err := makeDSes(cdn, domain, db)
if err != nil {
t.Fatalf("makeDSes expected: nil error, actual: %v", err)
}
@@ -310,6 +311,7 @@ func TestGetDSRegexesDomains(t *testing.T) {
defer db.Close()
cdn := "mycdn"
+ domain := "mycdn.invalid"
expectedMakeDSes := ExpectedMakeDSes()
expectedServerProfileParams := ExpectedGetServerProfileParams(expectedMakeDSes)
@@ -320,7 +322,7 @@ func TestGetDSRegexesDomains(t *testing.T) {
expectedMatchsets, expectedDomains := ExpectedGetDSRegexesDomains(expectedDSParams)
MockGetDSRegexesDomains(mock, expectedMatchsets, expectedDomains, cdn)
- actualMatchsets, actualDomains, err := getDSRegexesDomains(cdn, db, expectedDSParams)
+ actualMatchsets, actualDomains, err := getDSRegexesDomains(cdn, domain, db)
if err != nil {
t.Fatalf("getDSRegexesDomains expected: nil error, actual: %v", err)
}
--
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.