You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/11/06 22:17:49 UTC

[trafficcontrol] branch master updated: resolve unit test errors with no active cluster

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

dangogh 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 a9a6f0b  resolve unit test errors with no active cluster
a9a6f0b is described below

commit a9a6f0b439ea81342056be62bc0786da9078ad19
Author: Brian Olsen <br...@comcast.com>
AuthorDate: Tue Nov 6 22:01:44 2018 +0000

    resolve unit test errors with no active cluster
---
 .../traffic_ops_golang/riaksvc/riak_services.go    |  2 +-
 .../riaksvc/riak_services_test.go                  | 29 +++++++++++-----------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/riaksvc/riak_services.go b/traffic_ops/traffic_ops_golang/riaksvc/riak_services.go
index 1933879..10ef7c3 100644
--- a/traffic_ops/traffic_ops_golang/riaksvc/riak_services.go
+++ b/traffic_ops/traffic_ops_golang/riaksvc/riak_services.go
@@ -338,7 +338,7 @@ func GetPooledCluster(tx *sql.Tx, authOptions *riak.AuthOptions) (StorageCluster
 
 	if cluster == nil {
 		log.Errorln("GetPooledCluster failed, returning nil cluster")
-		return nil, errors.New("GetPooledClusterTX unable to return cluster")
+		return nil, errors.New("GetPooledCluster unable to return cluster")
 	}
 
 	return RiakStorageCluster{Cluster: cluster}, nil
diff --git a/traffic_ops/traffic_ops_golang/riaksvc/riak_services_test.go b/traffic_ops/traffic_ops_golang/riaksvc/riak_services_test.go
index 4d6a01c..fc63c8c 100644
--- a/traffic_ops/traffic_ops_golang/riaksvc/riak_services_test.go
+++ b/traffic_ops/traffic_ops_golang/riaksvc/riak_services_test.go
@@ -153,10 +153,6 @@ func TestGetRiakCluster(t *testing.T) {
 	rows1 := sqlmock.NewRows([]string{"fqdn"})
 	rows1.AddRow("www.devnull.com")
 
-	mock.ExpectQuery("SELECT").WillReturnError(errors.New("foo"))
-
-	mock.ExpectQuery("SELECT").WillReturnRows(rows1)
-
 	dbCtx, _ := context.WithTimeout(context.TODO(), time.Duration(10)*time.Second)
 	tx, err := db.BeginTx(dbCtx, nil)
 	if err != nil {
@@ -164,7 +160,18 @@ func TestGetRiakCluster(t *testing.T) {
 	}
 	defer tx.Commit()
 
-	if _, err := GetRiakCluster(tx, nil); err == nil {
+	mock.ExpectQuery("SELECT").WillReturnError(errors.New("foo"))
+	if _, err := GetRiakServers(tx); err == nil {
+		t.Errorf("expected an error retrieving nil servers.")
+	}
+
+	mock.ExpectQuery("SELECT").WillReturnRows(rows1)
+	servers, err := GetRiakServers(tx)
+	if err != nil {
+		t.Errorf("expected to receive servers: %v", err)
+	}
+
+	if _, err := GetRiakCluster(servers, nil); err == nil {
 		t.Errorf("expected an error due to nil RiakAuthoptions in the config but, go no error.")
 	}
 
@@ -174,21 +181,13 @@ func TestGetRiakCluster(t *testing.T) {
 		TlsConfig: &tls.Config{},
 	}
 
-	if _, err := GetRiakCluster(tx, &authOptions); err != nil {
-		t.Errorf("expected no errors, actual: %s.", err)
-	}
-
-	if _, err := GetPooledCluster(tx, &authOptions); err != nil {
-		t.Errorf("expected no errors, actual: %s.", err)
+	if _, err := GetRiakCluster(servers, &authOptions); err != nil {
+		t.Errorf("expected no errors, actual: %v", err)
 	}
 
 	rows2 := sqlmock.NewRows([]string{"s.host_name", "s.domain_name"})
 	mock.ExpectQuery("SELECT").WillReturnRows(rows2)
 
-	if _, err := GetRiakCluster(tx, &authOptions); err == nil {
-		t.Errorf("expected an error due to no available riak servers.")
-	}
-
 	if _, err := GetPooledCluster(tx, &authOptions); err == nil {
 		t.Errorf("expected an error due to no available riak servers.")
 	}