zrhoffman commented on a change in pull request #5017:
URL: https://github.com/apache/trafficcontrol/pull/5017#discussion_r489776654
##########
File path:
traffic_ops/traffic_ops_golang/deliveryservicesregexes/deliveryservicesregexes_test.go
##########
@@ -25,42 +26,64 @@ import (
* under the License.
*/
-func TestValidateDSRegexOrder(t *testing.T) {
- expected := `cannot add regex, another regex with the same order exists`
+func TestValidateDSRegexOrderExisting(t *testing.T) {
+ expected := `'setNumber' cannot add regex, another regex with the same
order exists`
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{"deliveryservice"}
+ cols := []string{"name", "use_in_table"}
rows := sqlmock.NewRows(cols)
rows = rows.AddRow(
+ "HTTP",
+ "regex",
+ )
+ cols2 := []string{"deliveryservice"}
+ rows2 := sqlmock.NewRows(cols2)
+ rows2 = rows2.AddRow(
1,
)
+
+ regex := tc.DeliveryServiceRegexPost{Type: 33, SetNumber: 3, Pattern:
".*"}
mock.ExpectBegin()
- mock.ExpectQuery("select").WithArgs(1, 3).WillReturnRows(rows)
+ mock.ExpectQuery("select").WithArgs(1,
regex.SetNumber).WillReturnRows(rows2)
+ mock.ExpectQuery("SELECT").WithArgs(regex.Type).WillReturnRows(rows)
+ mock.ExpectCommit()
tx := db.MustBegin().Tx
- err = validateDSRegexOrder(tx, 1, 3)
+ err = validateDSRegex(tx, regex, 1)
if err == nil {
- t.Fatal("Expected error but got nil")
+ t.Fatalf("Expected error %v but got none", expected)
Review comment:
Nit: Since the error references another error, `%v` should be `'%v'` for
clarity
##########
File path:
traffic_ops/traffic_ops_golang/deliveryservicesregexes/deliveryservicesregexes_test.go
##########
@@ -1,6 +1,7 @@
package deliveryservicesregexes
import (
Review comment:
Nit: Imports should be below the license. I know there's some files with
imports above the license, but we should fix those at some point, too.
##########
File path: traffic_ops/v3-client/deliveryservice_regexes.go
##########
@@ -39,3 +43,23 @@ func (to *Session) GetDeliveryServiceRegexesByDSID(dsID int,
params map[string]s
}
return response.Response, reqInf, nil
}
+
+func (to *Session) PostDeliveryServiceRegexesByDSID(dsID int, regex
tc.DeliveryServiceRegexPost) (tc.Alerts, ReqInf, error) {
+ var alerts tc.Alerts
+ var remoteAddr net.Addr
+ reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr:
remoteAddr}
+ reqBody, err := json.Marshal(regex)
+ if err != nil {
+ return alerts, reqInf, err
+ }
+
+ resp, remoteAddr, err := to.request(http.MethodPost,
fmt.Sprintf(API_DS_POST_REGEXES, dsID), reqBody, nil)
+ reqInf.RemoteAddr = remoteAddr
+ reqInf.StatusCode = resp.StatusCode
Review comment:
If `resp` is `nil`, this will segfault.
##########
File path: traffic_ops/v2-client/deliveryservice_regexes.go
##########
@@ -16,14 +16,18 @@
package client
import (
+ "encoding/json"
"fmt"
+ "net"
+ "net/http"
"github.com/apache/trafficcontrol/lib/go-tc"
)
const (
// See:
https://traffic-control-cdn.readthedocs.io/en/latest/api/v2/deliveryservices_id_regexes.html
- API_DS_REGEXES = apiBase + "/deliveryservices/%v/regexes"
+ API_DS_REGEXES = apiBase + "/deliveryservices/%v/regexes"
+ API_DS_POST_REGEXES = apiBase + "/deliveryservices/%v/regexes"
Review comment:
Same here: Since these constants have identical values, do we need both?
##########
File path: traffic_ops/v3-client/deliveryservice_regexes.go
##########
@@ -16,14 +16,18 @@
package client
import (
+ "encoding/json"
"fmt"
+ "net"
+ "net/http"
"github.com/apache/trafficcontrol/lib/go-tc"
)
const (
// See:
https://traffic-control-cdn.readthedocs.io/en/latest/api/v3/deliveryservices_id_regexes.html
- API_DS_REGEXES = apiBase + "/deliveryservices/%v/regexes"
+ API_DS_REGEXES = apiBase + "/deliveryservices/%v/regexes"
+ API_DS_POST_REGEXES = apiBase + "/deliveryservices/%v/regexes"
Review comment:
Since these constants have identical values, do we need both?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]