Skip to content

Commit

Permalink
Copy genericOKResponse from PR #107
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Dimjašević committed Nov 26, 2019
1 parent e655106 commit 5de5ff8
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions test/Fencer/Server/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ test_serverResponseReadPermissions =
response <- Proto.rateLimitServiceShouldRateLimit service $
Grpc.ClientNormalRequest request 1 mempty
expectSuccess
(expectedResponse, Grpc.StatusOk)
(genericOKResponse, Grpc.StatusOk)
response
where
files :: [RuleFile]
Expand All @@ -239,20 +239,6 @@ test_serverResponseReadPermissions =
, Proto.rateLimitRequestHitsAddend = 0
}

expectedResponse :: Proto.RateLimitResponse
expectedResponse = Proto.RateLimitResponse
{ rateLimitResponseOverallCode =
Enumerated $ Right Proto.RateLimitResponse_CodeOK
, rateLimitResponseStatuses = Vector.singleton
Proto.RateLimitResponse_DescriptorStatus
{ rateLimitResponse_DescriptorStatusCode =
Enumerated $ Right Proto.RateLimitResponse_CodeOK
, rateLimitResponse_DescriptorStatusCurrentLimit = Nothing
, rateLimitResponse_DescriptorStatusLimitRemaining = 0
}
, rateLimitResponseHeaders = Vector.empty
}

-- | A parameterized test that checks if a request with a non-empty
-- descriptor list results in a response with an unknown status code
-- in presence of a configuration with a duplicate domain/rule.
Expand Down Expand Up @@ -328,12 +314,6 @@ test_serverResponseDuplicateRule =
-- Helpers
----------------------------------------------------------------------------

domainDefinitionWithoutRules :: DomainDefinition
domainDefinitionWithoutRules = DomainDefinition
{ domainDefinitionId = DomainId "domain"
, domainDefinitionDescriptors = []
}

-- | Assert that a gRPC request is successful and has a specific result and
-- status code.
expectSuccess
Expand Down Expand Up @@ -469,3 +449,29 @@ withService server act =
Grpc.withGRPCClient (clientConfig (serverPort server)) $ \grpcClient -> do
service <- Proto.rateLimitServiceClient grpcClient
act service

----------------------------------------------------------------------------
-- Various useful values
----------------------------------------------------------------------------

domainDefinitionWithoutRules :: DomainDefinition
domainDefinitionWithoutRules = DomainDefinition
{ domainDefinitionId = DomainId "domain"
, domainDefinitionDescriptors = []
}

-- | A generic response useful for testing situations where the server
-- replies with a generic OK response.
genericOKResponse :: Proto.RateLimitResponse
genericOKResponse = Proto.RateLimitResponse
{ rateLimitResponseOverallCode =
Enumerated $ Right Proto.RateLimitResponse_CodeOK
, rateLimitResponseStatuses = Vector.singleton
Proto.RateLimitResponse_DescriptorStatus
{ rateLimitResponse_DescriptorStatusCode =
Enumerated $ Right Proto.RateLimitResponse_CodeOK
, rateLimitResponse_DescriptorStatusCurrentLimit = Nothing
, rateLimitResponse_DescriptorStatusLimitRemaining = 0
}
, rateLimitResponseHeaders = Vector.empty
}

0 comments on commit 5de5ff8

Please sign in to comment.