@@ -48,38 +48,79 @@ func testSimpleApp(t *testing.T, context spec.G, it spec.S) {
4848 Expect (docker .Volume .Remove .Execute (occam .CacheVolumeNames (name ))).To (Succeed ())
4949 })
5050
51- it ("creates a working OCI image with a rackup start command" , func () {
52- var err error
53- var logs fmt.Stringer
54- image , logs , err = pack .WithNoColor ().Build .
55- WithBuildpacks (mriBuildpack , bundlerBuildpack , bundleInstallBuildpack , rackupBuildpack ).
56- WithNoPull ().
57- Execute (name , filepath .Join ("testdata" , "simple_app" ))
58- Expect (err ).NotTo (HaveOccurred (), logs .String ())
59-
60- container , err = docker .Container .Run .WithEnv (map [string ]string {"PORT" : "9292" }).Execute (image .ID )
61- Expect (err ).NotTo (HaveOccurred ())
51+ context ("a container port is specified" , func () {
52+ it ("creates a working OCI image with a rackup start command" , func () {
53+ var err error
54+ var logs fmt.Stringer
55+ image , logs , err = pack .WithNoColor ().Build .
56+ WithBuildpacks (mriBuildpack , bundlerBuildpack , bundleInstallBuildpack , rackupBuildpack ).
57+ WithNoPull ().
58+ Execute (name , filepath .Join ("testdata" , "simple_app" ))
59+ Expect (err ).NotTo (HaveOccurred (), logs .String ())
60+
61+ container , err = docker .Container .Run .WithEnv (map [string ]string {"PORT" : "8088" }).Execute (image .ID )
62+ Expect (err ).NotTo (HaveOccurred ())
63+
64+ Eventually (container ).Should (BeAvailable (), ContainerLogs (container .ID ))
65+
66+ _ , exists := container .Ports ["8088" ]
67+ Expect (exists ).To (BeTrue ())
68+
69+ response , err := http .Get (fmt .Sprintf ("http://localhost:%s" , container .HostPort ()))
70+ Expect (err ).NotTo (HaveOccurred ())
71+ defer response .Body .Close ()
72+
73+ Expect (response .StatusCode ).To (Equal (http .StatusOK ))
74+
75+ content , err := ioutil .ReadAll (response .Body )
76+ Expect (err ).NotTo (HaveOccurred ())
77+ Expect (string (content )).To (ContainSubstring ("Hello world!" ))
78+
79+ buildpackVersion , err := GetGitVersion ()
80+ Expect (err ).ToNot (HaveOccurred ())
81+
82+ Expect (logs ).To (ContainLines (
83+ fmt .Sprintf ("Rackup Buildpack %s" , buildpackVersion ),
84+ " Writing start command" ,
85+ ` bundle exec rackup -p "${PORT:-9292}"` ,
86+ ))
87+ })
88+ })
6289
63- Eventually (container ).Should (BeAvailable (), ContainerLogs (container .ID ))
90+ context ("no container port is specified" , func () {
91+ it ("creates a working OCI image with a rackup start command" , func () {
92+ var err error
93+ var logs fmt.Stringer
94+ image , logs , err = pack .WithNoColor ().Build .
95+ WithBuildpacks (mriBuildpack , bundlerBuildpack , bundleInstallBuildpack , rackupBuildpack ).
96+ WithNoPull ().
97+ Execute (name , filepath .Join ("testdata" , "simple_app" ))
98+ Expect (err ).NotTo (HaveOccurred (), logs .String ())
6499
65- response , err := http .Get (fmt .Sprintf ("http://localhost:%s" , container .HostPort ()))
66- Expect (err ).NotTo (HaveOccurred ())
67- defer response .Body .Close ()
100+ container , err = docker .Container .Run .Execute (image .ID )
101+ Expect (err ).NotTo (HaveOccurred ())
68102
69- Expect ( response . StatusCode ). To ( Equal ( http . StatusOK ))
103+ Eventually ( container ). Should ( BeAvailable (), ContainerLogs ( container . ID ))
70104
71- content , err := ioutil .ReadAll (response .Body )
72- Expect (err ).NotTo (HaveOccurred ())
73- Expect (string (content )).To (ContainSubstring ("Hello world!" ))
105+ response , err := http .Get (fmt .Sprintf ("http://localhost:%s" , container .HostPort ()))
106+ Expect (err ).NotTo (HaveOccurred ())
107+ defer response .Body .Close ()
108+
109+ Expect (response .StatusCode ).To (Equal (http .StatusOK ))
110+
111+ content , err := ioutil .ReadAll (response .Body )
112+ Expect (err ).NotTo (HaveOccurred ())
113+ Expect (string (content )).To (ContainSubstring ("Hello world!" ))
74114
75- buildpackVersion , err := GetGitVersion ()
76- Expect (err ).ToNot (HaveOccurred ())
115+ buildpackVersion , err := GetGitVersion ()
116+ Expect (err ).ToNot (HaveOccurred ())
77117
78- Expect (logs ).To (ContainLines (
79- fmt .Sprintf ("Rackup Buildpack %s" , buildpackVersion ),
80- " Writing start command" ,
81- " `bundle exec rackup -p ${PORT}`" ,
82- ))
118+ Expect (logs ).To (ContainLines (
119+ fmt .Sprintf ("Rackup Buildpack %s" , buildpackVersion ),
120+ " Writing start command" ,
121+ ` bundle exec rackup -p "${PORT:-9292}"` ,
122+ ))
123+ })
83124 })
84125 })
85126}
0 commit comments