mhoppa commented on a change in pull request #4406: Only allow changing of 
types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387684506
 
 

 ##########
 File path: traffic_ops/testing/api/v2/types_test.go
 ##########
 @@ -31,50 +32,78 @@ func TestTypes(t *testing.T) {
 func CreateTestTypes(t *testing.T) {
        t.Log("---- CreateTestTypes ----")
 
+       db, err := OpenConnection()
+       if err != nil {
+               t.Fatal("cannot open db")
+       }
+       defer func() {
+               err := db.Close()
+               if err != nil {
+                       t.Errorf("unable to close connection to db, error: %v", 
err.Error())
+               }
+       }()
+       dbQueryTemplate := "INSERT INTO type (name, description, use_in_table) 
VALUES ('%v', '%v', '%v');"
+
        for _, typ := range testData.Types {
-               resp, _, err := TOSession.CreateType(typ)
+               foundTypes, _, err := TOSession.GetTypeByName(typ.Name)
+               if err == nil && len(foundTypes) > 0 {
+                       t.Logf("Type %v already exists (%v match(es))", 
typ.Name, len(foundTypes))
+                       continue
+               }
+
+               if typ.UseInTable != "server" {
+                       err = execSQL(db, fmt.Sprintf(dbQueryTemplate, 
typ.Name, typ.Description, typ.UseInTable), "type")
+               } else {
+                       _, _, err = TOSession.CreateType(typ)
+               }
+
                if err != nil {
                        t.Errorf("could not CREATE types: %v", err)
                }
-               t.Log("Response: ", resp)
        }
 
 }
 
 func UpdateTestTypes(t *testing.T) {
        t.Log("---- UpdateTestTypes ----")
+       expectedTypeName := "testType%v"
 
 Review comment:
   nit but does this need to be in a variable? can it just directly go into the 
Sprintf below? 

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to