Skip to content

Instantly share code, notes, and snippets.

View mucahitkurt's full-sized avatar

Mucahit Kurt mucahitkurt

View GitHub Profile
class OrderService(val orderRepository: OrderRepository) {
fun cancelAllOrder(customer: Customer) {
val orders = orderRepository.findAllByCustomerAndOrderStatus(customer, OrderStatus.UNPAID)
//..
}
}
class OrderServiceTest {
@Test
fun `Should cancel all order of a customer if the all orders are unpaid`() {
@Test
fun `Should be cancelled if the order is unpaid`() {
//...
}
@Test
fun `Should be cancelled if the order is unpaid`() {
//Arrange
val order = Order(OrderSpecification())
order.makeUnpaid()
//Act
order.cancel()
//Assert
class OrderSpecification {
fun isCancellable(orderStatus: OrderStatus): Boolean {
//…check order status
return true
}
}
class OrderTest() {
//…
@Test
fun `Should be cancelled if the order is unpaid`() {
val order = Order(OrderSpecification())
//…make the order unpaid…
order.cancel()
Assertions.assertTrue(order.isCancelled())
}
}
class OrderTest() {
//…
@Test
fun `Should be cancelled if the order is unpaid`() {
val orderSpecification = mockk<OrderSpecification>(relaxed = true)
val order = Order(orderSpecification)
//…make the order unpaid…
every { orderSpecification.isCancellable(order) } returns true
order.cancel()
class InvalidOrderStateToCancel: RuntimeException()
class Order(val orderSpecification: OrderSpecification) {
fun cancel() {
if (!orderSpecification.isCancellable(this)) {
throw InvalidOrderStateToCancel()
}
//…cancel order
}
@mucahitkurt
mucahitkurt / fetch_podstartup_times.py
Created July 26, 2019 23:37
script to fetch pod startup latency test results for k8s storage performance tests
from lxml import html
import requests
import json
def find_build_ids(test_case='max-emptydir-vol-per-pod'):
page = requests.get('https://gcsweb.k8s.io/gcs/kubernetes-jenkins/logs/ci-kubernetes-storage-scalability-{}/'.format(test_case))
tree = html.fromstring(page.content)
raw_build_ids = tree.xpath('//li[@class="pure-g grid-row"]/div[@class="pure-u-2-5"]/a/text()')