免责声明:我是 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
当我运行它时,我得到它显示预期为空白,看起来它没有运行并返回任何东西
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