restore_registry: &RESTORE_REGISTRY
  restore_cache:
    key: registry
save_registry: &SAVE_REGISTRY
  save_cache:
    key: registry-{{ .BuildNum }}
    paths:
    - /usr/local/cargo/registry/index
deps_key: &DEPS_KEY
  key: deps-{{ checksum "~/rust-version" }}-{{ checksum "Cargo.lock" }}
restore_deps: &RESTORE_DEPS
  restore_cache:
    <<: *DEPS_KEY
save_deps: &SAVE_DEPS
  save_cache:
    <<: *DEPS_KEY
    paths:
    - target
    - /usr/local/cargo/registry/cache

version: 2
jobs:
  build:
    docker:
      - image: rust:1.19.0
    working_directory: ~/build
    environment:
      RUSTFLAGS: -D warnings
    steps:
      - checkout
      - run: apt-get update
      - run: apt-get install -y --no-install-recommends dante-server
      - run: danted -D -f .circleci/danted_no_auth.conf
      - run: danted -D -f .circleci/danted_password.conf
      - run: useradd testuser -p '$1$DLEVM6FQ$dNm6etLDprLfwWSLCUtQY/'  # password: testpass
      - *RESTORE_REGISTRY
      - run: cargo generate-lockfile
      - *SAVE_REGISTRY
      - run: rustc --version > ~/rust-version
      - *RESTORE_DEPS
      - run: cargo test
      - *SAVE_DEPS
