ocket8888 commented on a change in pull request #4006: implement deliveryservice_server_capabilities api endpoint URL: https://github.com/apache/trafficcontrol/pull/4006#discussion_r337750113
########## File path: traffic_ops/traffic_ops_golang/deliveryservice/deliveryservice_server_capabilities_test.go ########## @@ -0,0 +1,188 @@ +package deliveryservice + +/* + * 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 ( + "fmt" + "net/http" + "testing" + "time" + + "github.com/apache/trafficcontrol/lib/go-tc" + "github.com/apache/trafficcontrol/lib/go-util" + + "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api" + "github.com/jmoiron/sqlx" + sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1" +) + +func TestDeliveryServiceServerCapabilityInterfaces(t *testing.T) { + var i interface{} + i = &ServerCapability{} + + if _, ok := i.(api.Creator); !ok { + t.Errorf("DeliveryServiceServerCapability must be Creator") + } + if _, ok := i.(api.Reader); !ok { + t.Errorf("DeliveryServiceServerCapability must be Reader") + } + if _, ok := i.(api.Deleter); !ok { + t.Errorf("DeliveryServiceServerCapability must be Deleter") + } + if _, ok := i.(api.Identifier); !ok { + t.Errorf("DeliveryServiceServerCapability must be Identifier") + } +} + +func TestCreateDeliveryServiceServerCapability(t *testing.T) { + mockDB, mock, err := sqlmock.New() + if err != nil { + t.Fatalf(err.Error()) + } + defer mockDB.Close() + + db := sqlx.NewDb(mockDB, "sqlmock") + defer db.Close() + + mock.ExpectBegin() + sc := ServerCapability{ + api.APIInfoImpl{ + ReqInfo: &api.APIInfo{Tx: db.MustBegin()}, + }, + tc.DeliveryServiceServerCapability{}, + } + + rows := sqlmock.NewRows([]string{"server_capability", "deliveryservice_id", "last_updated"}).AddRow( + util.StrPtr("mem"), + util.IntPtr(1), + time.Now(), + ) + mock.ExpectQuery("INSERT*").WillReturnRows(rows) Review comment: FWIW a bunch of our `INSERT` queries will return rows via the `RETURNING` clause. Dunno if that's what's supposed to happen here or not. Those typically use [`database/sql.Tx.QueryRow`](https://godoc.org/database/sql#Tx.QueryRow). ---------------------------------------------------------------- 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
