You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/11/06 22:17:46 UTC

[GitHub] dangogh closed pull request #2996: resolve unit test errors with no active cluster

dangogh closed pull request #2996: resolve unit test errors with no active cluster
URL: https://github.com/apache/trafficcontrol/pull/2996
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_ops/traffic_ops_golang/riaksvc/riak_services.go b/traffic_ops/traffic_ops_golang/riaksvc/riak_services.go
index 193387929..10ef7c306 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 4d6a01c03..fc63c8c56 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.")
 	}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services