8 Aralık 2022 Perşembe

Docker Compose ve WireMock - Sunucudan Gelen Cevap Gibidir

Örnek
Şöyle yaparız
version: '3.9'

services:
  todo-service:
    image: wiremock/wiremock:2.32.0
    container_name: todo-service
    volumes:
      - ./local-setup:/home/wiremock
    ports:
      - 8383:8080
local-setup/mappings dizininde json scriptl'leri vardır. Dizin yapısı şöyle. __files dizini WireMock tarafından otomatik yaratılıyor
local_setup
  __files
  mapppings
docker-compose.yml
json dosyaları şöyledir
//get-todos.json
docker-compose.yml{
    "request": {
        "method": "GET",
        "urlPathPattern": "/api/v1/todos"
    },
    "response": {
        "status": 200,
        "jsonBody": [
            {
                "id": "d8b25784-c16f-449a-9006-6972e8a9111b",
                "title": "Clean House",
                "active": true,
                "created": "2022-04-11"
            },
            {
                "id": "38ab7f0f-0cdc-4643-8cdb-42acf7d1a4c4",
                "title": "Clean Car",
                "active": true,
                "created": "2022-04-12"
            }
        ],
        "headers": {
            "Content-Type": "application/json"
        }
    }
}

//get-todo.json
{
  "request": {
    "method": "GET",
    "urlPathPattern": "/api/v1/todos/d8b25784-c16f-449a-9006-6972e8a9111b"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "id": "d8b25784-c16f-449a-9006-6972e8a9111b",
      "title": "Clean House",
      "active": true,
      "created": "2022-04-11"
    },
    "headers": {
      "Content-Type": "application/json"
    }
  }
}

//get-todo-not-found.json
{
    "priority": 2,
    "request": {
        "method": "GET",
        "urlPathPattern": "/api/v1/todos/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
    },
    "response": {
        "status": 404,
        "headers": {
            "Content-Type": "application/json"
        }
    }
}




Hiç yorum yok:

Yorum Gönder