ocket8888 commented on a change in pull request #3478: Mock Traffic Ops Server
URL: https://github.com/apache/trafficcontrol/pull/3478#discussion_r275044667
 
 

 ##########
 File path: traffic_ops/client_tests/cachegroups.go
 ##########
 @@ -0,0 +1,99 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import "net/http"
+
+import "github.com/apache/trafficcontrol/lib/go-tc"
+import "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+
+// Static Cache Group fields
+var EDGE_CACHEGROUP_ID = 1
+var EDGE_CACHEGROUP = "Edge"
+var EDGE_CACHEGROUP_SHORT_NAME = "Edge"
+var EDGE_CACHEGROUP_LATITUDE = 0.0
+var EDGE_CACHEGROUP_LONGITUDE = 0.0
+var EDGE_CACHEGROUP_PARENT_NAME = "Mid" // NOTE: This places a hard 
requirement on the `cachegroups` implementation - must have a `MID_LOC` Cache 
Group named "Mid"
+var EDGE_CACHEGROUP_PARENT_ID = 2       // NOTE: This places a hard 
requirement on the `cachegroups` implementation - must have a `MID_LOC` Cache 
Group identified by `2`
+var EDGE_CACHEGROUP_FALLBACK_TO_CLOSEST = true
+var EDGE_CACHEGROUP_LOCALIZATION_METHODS = []tc.LocalizationMethod{
+       tc.LocalizationMethodCZ,
+       tc.LocalizationMethodDeepCZ,
+       tc.LocalizationMethodGeo,
+}
+
+var MID_CACHEGROUP_ID = 2
+var MID_CACHEGROUP = "Mid"
+var MID_CACHEGROUP_SHORT_NAME = "Mid"
+var MID_CACHEGROUP_LATITUDE = 0.0
+var MID_CACHEGROUP_LONGITUDE = 0.0
+var MID_CACHEGROUP_FALLBACK_TO_CLOSEST = true
+var MID_CACHEGROUP_LOCALIZATION_METHODS = []tc.LocalizationMethod{
+       tc.LocalizationMethodCZ,
+       tc.LocalizationMethodDeepCZ,
+       tc.LocalizationMethodGeo,
+}
+
+var CACHEGROUPS = []tc.CacheGroupNullable{
 
 Review comment:
   > _"we can just create static JSON files that are served up by a simple http 
server in a simple directory structure"_
   
   Yeah we could. My concern with that is double-maintenance of values. Like, 
right now, I have the parent of the edge cache group set to a pointer to the 
name of the mid cache group. That way you only have to change it once. If 
they're in JSON, we lose the ability to make those connections, unless we're 
going to do text replacements which once again more or less ends with us having 
all the values statically defined in the Go code anyway.
   
   > _"Have you considered writing a UT suite against ORT and then mocking out 
the specific calls it will make on a function by function basis?"_
   
   That's more or less what I'm doing. Thing is, we have ORT.pl and my baby, 
ORT.py. I want the tests to be independent of implementation, i.e. "after a 
SYNCDS run of an ORT implementation pointed at the Mock TO, the exact file 
system and process table changes should be this:". Building tests into the Perl 
code limits my ability to to test Python, and vice-versa. Basically the entire 
reason I wanted a mock TO in the first place was to figure out what gaps there 
still are between the two implementations.
   
   What I've done here is build a fake HTTP service that ORT requires to run, 
which is the first step in writing the actual tests. By separating them, I can 
make a more general-purpose testing tool that could be used by more 
general-purpose clients, like the Apache-TrafficControl Python package and the 
Golang client @rawlinp mentioned.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to