2017-05-11 7 views
1

부인 실패 : 나는 루비에 새로운 오전, 등 RSpec에 나는 내가 AWS CLI 실행되는 고정 표시기 용기를 내 고정 표시기 용기 RSpec에 테스트 도커 용기에

에 대한 테스트 프레임 워크를 찾기 위해 노력하고있다. 이 테스트를 수동으로 수행했는데 AWS 버전을 가져 와서 테스트하고 싶습니다. 내가 그것을 실행하면

나는 그것이 내 모든 다른 테스트를 실행하고 새로운 것을

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)>' 

을 반환하지 않습니다처럼, 그것은 빈 보이는 exepected 보여주는 얻을이 시험

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

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

을 만들었습니다 컨테이너에 대해 올바르게 작동하십시오. 나는

Dockerfile 아래에있는 내 dockerfile 및 test_spec을 모두 포함했다 :

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 

답변

0

아주 간단한 (하지만 나에게 발견하는 걸 렸어요) : 몇 가지 이유 aws --version에 대한 명령 펌프는 stdout이 아닌 stderr에 출력됩니다. 그래서 그 대신 이렇게 :

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

또한, 모든 컨테이너는 기본적으로 수행하는 aws --version 명령을 실행 한 후 종료되는 것을 주목할 가치가있다. 따라서 사양이 충분히 빠르게 실행되는 한 괜찮을 것입니다.하지만 그렇지 않으면 무작위로 실패 할 것입니다. 귀하의 사양 나는 이미지의 기본 엔트리 포인트/cmd를 무시하고 after 블록 컨테이너를 죽이는 때까지 살아 남아 있도록 간단한 while true; do sleep 100; done에 넣어 줄에서

.