---
setup:

  - do:
      snapshot.create_repository:
        repository: test_repo_restore_1
        body:
          type: fs
          settings:
            location: "test_repo_restore_1_loc"

  - do:
      indices.create:
        index: test_index
        body:
          settings:
            number_of_shards:   1
            number_of_replicas: 0

  - do:
      cluster.health:
        wait_for_status: green

---
"Create a snapshot and then restore it":

  - do:
      snapshot.create:
        repository: test_repo_restore_1
        snapshot: test_snapshot
        wait_for_completion: true

  - match: { snapshot.snapshot: test_snapshot }
  - match: { snapshot.state : SUCCESS }
  - match: { snapshot.shards.successful: 1 }
  - match: { snapshot.shards.failed : 0 }
  - is_true: snapshot.version
  - gt: { snapshot.version_id: 0}

  - do:
      indices.close:
        index : test_index

  - do:
      snapshot.restore:
        repository: test_repo_restore_1
        snapshot: test_snapshot
        wait_for_completion: true

  - do:
      indices.recovery:
        index: test_index

  - match: { test_index.shards.0.type: SNAPSHOT }
  - match: { test_index.shards.0.stage: DONE }
  - match: { test_index.shards.0.index.files.recovered: 0}
  - match: { test_index.shards.0.index.size.recovered_in_bytes: 0}
  - match: { test_index.shards.0.index.files.reused: 1}
  - gt: { test_index.shards.0.index.size.reused_in_bytes: 0}
