1

免責事項: 私は ruby​​ や rspec などは初めてです。docker コンテナーのテスト フレームワークを見つけようとしています。

aws cli を実行する docker コンテナがあります。これを手動でテストしましたが、動作します。テストの一環として、AWS のバージョンを取得して確認したいと考えています。

このテストを作成しました

it "aws is the correct version" do
  expect(aws_version).to include("aws")
end

def aws_version
 command("aws --version").stdout
end

私がそれを実行すると、expected が空であることを示すメッセージが表示されます。実行されておらず、何も返されていないように見えます

1) Dockerfile aws is the coorect version
     Failure/Error: expect(aws_version).to include("aws")
       expected "" to include "aws"

     # ./tests_spec.rb:37:in `block (2 levels) in <top (required)>'

私の他のすべてのテストは、コンテナーに対して正しく実行されます。dockerfile と test_spec の両方を以下に含めました

Dockerfile:

FROM ubuntu:16.04


ENV LAST_UPDATE=09-04-2017

#####################################################################################
# Current version is aws-cli/1.11.83 Python/2.7.12 Linux/4.4.0-75-generic botocore/1.5.46
#####################################################################################


RUN apt-get update && apt-get -y upgrade
RUN apt-get install python-pip -y
RUN pip install --upgrade pip
RUN pip install --upgrade awscli s3cmd python-magic
RUN export PATH=~/.local/bin:$PATH
RUN mkdir /root/.aws
COPY config /root/.aws
#COPY credentials /root/.aws
WORKDIR /root
ENTRYPOINT ["aws"]
CMD ["--version"]

test_spec.rb:

require "docker"
require "serverspec"

    describe "Dockerfile" do
      before(:all) do
        @image = Docker::Image.build_from_dir('.')

        set :os, family: :ubuntu
        set :backend, :docker
        set :docker_image, @image.id

      @container = Docker::Container.create(
          'Image'      => @image.id,
        )
        @container.start
      end

  it "installs the right version Name of  Ubuntu" do
    expect(os_version).to include("xenial")
  end

  it "installs the right version of Ubuntu" do
    expect(os_version).to include("Ubuntu 16.04.2")
  end

  it "installs required packages" do
   expect(package("python-pip")).to be_installed
  end


  it "aws is the coorect version" do
    expect(aws_version).to include("aws")
  end

  def aws_version
   command("aws --version").stdout
  end

  def os_version
    command("cat /etc/lsb-release").stdout
  end
    after(:all) do
      @container.kill
      @container.delete(:force => true)
    end
end
4

1 に答える 1