zrhoffman commented on a change in pull request #4718:
URL: https://github.com/apache/trafficcontrol/pull/4718#discussion_r430650582
##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +83,28 @@ func CreateTestInvalidationJobs(t *testing.T) {
}
}
+func CreateInvalidJob(t *testing.T) {
+ toDSes, _, err := TOSession.GetDeliveryServicesNullable()
+ if err != nil {
+ t.Fatalf("cannot GET Delivery Services: %v - %v", err, toDSes)
+ }
+ dsNameIDs := map[string]int64{}
+ for _, ds := range toDSes {
+ dsNameIDs[*ds.XMLID] = int64(*ds.ID)
+ }
+
+ job := testData.InvalidationJobs[0]
+ _, ok := dsNameIDs[(*job.DeliveryService).(string)]
+ if !ok {
+ t.Fatalf("can't create test data job: delivery service '%v' not
found in Traffic Ops", job.DeliveryService)
+ }
+ tooHigh := interface{}(2161)
+ job.TTL = &tooHigh
+ if _, _, err := TOSession.CreateInvalidationJob(job); err == nil {
+ t.Error("creating invalid job (TTL higher than
maxRevalDurationDays) - expected: error, actual: nil error")
+ }
Review comment:
Should assert the status code is 400-level
##########
File path: lib/go-tc/invalidationjobs.go
##########
@@ -349,12 +356,13 @@ func (job *UserInvalidationJobInput) Validate(tx *sql.Tx)
error {
if job.TTL != nil {
row := tx.QueryRow(`SELECT value FROM parameter WHERE
name='maxRevalDurationDays' AND config_file='regex_revalidate.config'`)
- var max uint64
- err := row.Scan(&max)
+ var maxDays uint64
+ err := row.Scan(&maxDays)
+ maxHours := maxDays * 24
if err == sql.ErrNoRows && MaxTTL < *(job.TTL) {
errs = append(errs, "ttl: cannot exceed
"+strconv.FormatUint(MaxTTL, 10)+"!")
- } else if err == nil && max < *(job.TTL) { //silently ignore
other errors to
- errs = append(errs, "ttl: cannot exceed
"+strconv.FormatUint(max, 10)+"!")
+ } else if err == nil && maxHours < *(job.TTL) { //silently
ignore other errors to
Review comment:
There's no better time to add an "o".
##########
File path: lib/go-tc/invalidationjobs.go
##########
@@ -349,12 +356,13 @@ func (job *UserInvalidationJobInput) Validate(tx *sql.Tx)
error {
if job.TTL != nil {
row := tx.QueryRow(`SELECT value FROM parameter WHERE
name='maxRevalDurationDays' AND config_file='regex_revalidate.config'`)
- var max uint64
- err := row.Scan(&max)
+ var maxDays uint64
+ err := row.Scan(&maxDays)
+ maxHours := maxDays * 24
if err == sql.ErrNoRows && MaxTTL < *(job.TTL) {
errs = append(errs, "ttl: cannot exceed
"+strconv.FormatUint(MaxTTL, 10)+"!")
- } else if err == nil && max < *(job.TTL) { //silently ignore
other errors to
- errs = append(errs, "ttl: cannot exceed
"+strconv.FormatUint(max, 10)+"!")
+ } else if err == nil && maxHours < *(job.TTL) { //silently
ignore other errors to
+ errs = append(errs, "ttl: cannot exceed
"+strconv.FormatUint(maxHours, 10)+"!")
Review comment:
Errors should not end with punctuation
##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +83,28 @@ func CreateTestInvalidationJobs(t *testing.T) {
}
}
+func CreateInvalidJob(t *testing.T) {
Review comment:
To follow naming conventions, this should be `CreateTestInvalidJob()`.
##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +83,28 @@ func CreateTestInvalidationJobs(t *testing.T) {
}
}
+func CreateInvalidJob(t *testing.T) {
+ toDSes, _, err := TOSession.GetDeliveryServicesNullable()
+ if err != nil {
+ t.Fatalf("cannot GET Delivery Services: %v - %v", err, toDSes)
+ }
+ dsNameIDs := map[string]int64{}
+ for _, ds := range toDSes {
+ dsNameIDs[*ds.XMLID] = int64(*ds.ID)
+ }
+
+ job := testData.InvalidationJobs[0]
+ _, ok := dsNameIDs[(*job.DeliveryService).(string)]
+ if !ok {
+ t.Fatalf("can't create test data job: delivery service '%v' not
found in Traffic Ops", job.DeliveryService)
+ }
+ tooHigh := interface{}(2161)
Review comment:
2160 is a well-known TTL, but this magic number should still be factored
into `x * y * [...]`
##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +83,28 @@ func CreateTestInvalidationJobs(t *testing.T) {
}
}
+func CreateInvalidJob(t *testing.T) {
+ toDSes, _, err := TOSession.GetDeliveryServicesNullable()
+ if err != nil {
+ t.Fatalf("cannot GET Delivery Services: %v - %v", err, toDSes)
+ }
+ dsNameIDs := map[string]int64{}
+ for _, ds := range toDSes {
+ dsNameIDs[*ds.XMLID] = int64(*ds.ID)
+ }
+
+ job := testData.InvalidationJobs[0]
+ _, ok := dsNameIDs[(*job.DeliveryService).(string)]
+ if !ok {
+ t.Fatalf("can't create test data job: delivery service '%v' not
found in Traffic Ops", job.DeliveryService)
+ }
+ tooHigh := interface{}(2161)
Review comment:
2160 is a well-known TTL, but this magic number should still be factored
into `x * y * [...] + 1`
##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +85,47 @@ func CreateTestInvalidationJobs(t *testing.T) {
}
}
+func CreateTestInvalidJob(t *testing.T) {
+ toDSes, _, err := TOSession.GetDeliveryServicesNullable()
+ if err != nil {
+ t.Fatalf("cannot GET Delivery Services: %v - %v", err, toDSes)
+ }
+ dsNameIDs := map[string]int64{}
+ for _, ds := range toDSes {
+ dsNameIDs[*ds.XMLID] = int64(*ds.ID)
+ }
+
+ job := testData.InvalidationJobs[0]
+ _, ok := dsNameIDs[(*job.DeliveryService).(string)]
+ if !ok {
+ t.Fatalf("can't create test data job: delivery service '%v' not
found in Traffic Ops", job.DeliveryService)
+ }
+ maxRevalDays := 0
+ foundMaxRevalDays := false
+ for _, p := range testData.Parameters {
+ if p.Name == "maxRevalDurationDays" {
+ maxRevalDays, err = strconv.Atoi(p.Value)
+ if err != nil {
+ t.Fatalf("unable to parse maxRevalDurationDays
value '%s' to int", p.Value)
+ }
+ foundMaxRevalDays = true
+ break
Review comment:
This block can be unindented if it's moved to after the `if` statement,
the condition is negated, and the loop `continue`s if the condition is met
----------------------------------------------------------------
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]