Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added more test cases for coverage
  • Loading branch information
anandrgitnirman committed May 27, 2022
1 parent fd387e1 commit f0d08f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
16 changes: 4 additions & 12 deletions training/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,9 @@ func (service ModelService) updateModelDetails(request *UpdateModelRequest, resp
latestAddresses = request.UpdateModelDetails.AddressList
}
latestAddresses = append(latestAddresses, request.Authorization.SignerAddress)
if data, err = service.getModelDataForUpdate(request, response); err == nil && data != nil {
if data, err = service.getModelDataForUpdate(request); err == nil && data != nil {
oldAddresses = data.AuthorizedAddresses
if latestAddresses == nil || len(latestAddresses) == 0 {
latestAddresses = make([]string, 0)
} else {
data.AuthorizedAddresses = latestAddresses
}
data.AuthorizedAddresses = latestAddresses
latestAddresses = append(latestAddresses, request.Authorization.SignerAddress)
data.IsPublic = request.UpdateModelDetails.IsPubliclyAccessible
data.UpdatedByAddress = request.Authorization.SignerAddress
Expand Down Expand Up @@ -296,12 +292,7 @@ func (service ModelService) getModelKeyToUpdate(request *UpdateModelRequest) (ke
return
}

func (service ModelService) getModelDataForUpdate(request *UpdateModelRequest, response *ModelDetailsResponse) (data *ModelData, err error) {
data, err = service.getModelDataForStatusUpdate(request, response)
return
}

func (service ModelService) getModelDataForStatusUpdate(request *UpdateModelRequest, response *ModelDetailsResponse) (data *ModelData, err error) {
func (service ModelService) getModelDataForUpdate(request *UpdateModelRequest) (data *ModelData, err error) {
key := service.getModelKeyToUpdate(request)
ok := false

Expand All @@ -310,6 +301,7 @@ func (service ModelService) getModelDataForStatusUpdate(request *UpdateModelRequ
}
return
}

func (service ModelService) GetAllModels(c context.Context, request *AccessibleModelsRequest) (response *AccessibleModelsResponse, err error) {
if request == nil || request.Authorization == nil {
return &AccessibleModelsResponse{},
Expand Down
20 changes: 12 additions & 8 deletions training/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ func (suite *ModelServiceTestSuite) TestModelService_remove() {
sample2 := []string{"b", "c"}
output := remove(sample1, "a")
assert.Equal(suite.T(), output, sample2)
output = remove(output, "a")
assert.Equal(suite.T(), output, sample2)
}

func (suite *ModelServiceTestSuite) TestModelService_difference() {
Expand All @@ -440,31 +442,33 @@ func (suite *ModelServiceTestSuite) TestModelService_isValuePresent() {
func (suite *ModelServiceTestSuite) TestModelService_UDeleteModel() {
response, err := suite.service.DeleteModel(context.Background(), nil)
assert.NotNil(suite.T(), err)

//unauthorized signer
request := &UpdateModelRequest{
UpdateModelDetails: &ModelDetails{
ModelId: "1",
GrpcServiceName: "TESTSERVICE",
GrpcMethodName: "TESTMETHOD",
},
Authorization: &AuthorizationDetails{
SignerAddress: suite.senderAddress.String(),
SignerAddress: suite.alternateUserAddress.String(),
Message: "__GetModelStatus",
Signature: suite.getSignature("__GetModelStatus", 1200, suite.senderPvtKy),
Signature: suite.getSignature("__GetModelStatus", 1200, suite.alternateUserPvtKy),
CurrentBlock: 1200,
},
}
fmt.Println(suite.senderAddress.String())
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2000)
defer cancel()
response, err = suite.service.DeleteModel(ctx, request)
assert.NotNil(suite.T(), err)

fmt.Println(suite.senderAddress.String())
//valid signer
request.Authorization.SignerAddress = suite.senderAddress.String()
request.Authorization.Signature = suite.getSignature("__GetModelStatus", 1200, suite.senderPvtKy)
response, err = suite.service.DeleteModel(ctx, request)
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), Status_DELETED, response.Status)

//unauthorized signer
request.Authorization.SignerAddress = suite.alternateUserAddress.String()
request.Authorization.Signature = suite.getSignature("__GetModelStatus", 1200, suite.alternateUserPvtKy)

//bad signer
request.Authorization.Message = "blah"
response, err = suite.service.DeleteModel(ctx, request)
Expand Down

0 comments on commit f0d08f8

Please sign in to comment.