summaryrefslogtreecommitdiffhomepage
path: root/runsc/test/image
diff options
context:
space:
mode:
Diffstat (limited to 'runsc/test/image')
-rw-r--r--runsc/test/image/BUILD2
-rw-r--r--runsc/test/image/image_test.go49
-rw-r--r--runsc/test/image/ruby.rb23
-rw-r--r--runsc/test/image/ruby.sh20
4 files changed, 94 insertions, 0 deletions
diff --git a/runsc/test/image/BUILD b/runsc/test/image/BUILD
index 5854eec12..c41161d50 100644
--- a/runsc/test/image/BUILD
+++ b/runsc/test/image/BUILD
@@ -11,6 +11,8 @@ go_test(
data = [
"latin10k.txt",
"mysql.sql",
+ "ruby.rb",
+ "ruby.sh",
],
embed = [":image"],
tags = [
diff --git a/runsc/test/image/image_test.go b/runsc/test/image/image_test.go
index 13fd8f1ee..5f90ca9d2 100644
--- a/runsc/test/image/image_test.go
+++ b/runsc/test/image/image_test.go
@@ -30,6 +30,7 @@ import (
"io/ioutil"
"net/http"
"os"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -256,6 +257,54 @@ func TestTomcat(t *testing.T) {
}
}
+func TestRuby(t *testing.T) {
+ if err := testutil.Pull("ruby"); err != nil {
+ t.Fatalf("docker pull failed: %v", err)
+ }
+ d := testutil.MakeDocker("ruby-test")
+
+ dir, err := testutil.PrepareFiles("ruby.rb", "ruby.sh")
+ if err != nil {
+ t.Fatalf("PrepareFiles() failed: %v", err)
+ }
+ if err := os.Chmod(filepath.Join(dir, "ruby.sh"), 0333); err != nil {
+ t.Fatalf("os.Chmod(%q, 0333) failed: %v", dir, err)
+ }
+
+ if _, err := d.Run("-p", "8080", "-v", testutil.MountArg(dir, "/src:ro"), "ruby", "/src/ruby.sh"); err != nil {
+ t.Fatalf("docker run failed: %v", err)
+ }
+ defer d.CleanUp()
+
+ // Find where port 8080 is mapped to.
+ port, err := d.FindPort(8080)
+ if err != nil {
+ t.Fatalf("docker.FindPort(8080) failed: %v", err)
+ }
+
+ // Wait until it's up and running, 'gem install' can take some time.
+ if err := testutil.WaitForHTTP(port, 30*time.Second); err != nil {
+ t.Fatalf("WaitForHTTP() timeout: %v", err)
+ }
+
+ // Ensure that content is being served.
+ url := fmt.Sprintf("http://localhost:%d", port)
+ resp, err := http.Get(url)
+ if err != nil {
+ t.Errorf("error reaching http server: %v", err)
+ }
+ if want := http.StatusOK; resp.StatusCode != want {
+ t.Errorf("wrong response code, got: %d, want: %d", resp.StatusCode, want)
+ }
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ t.Fatalf("error reading body: %v", err)
+ }
+ if got, want := string(body), "Hello World"; !strings.Contains(got, want) {
+ t.Errorf("invalid body content, got: %q, want: %q", got, want)
+ }
+}
+
func MainTest(m *testing.M) {
testutil.EnsureSupportedDockerVersion()
os.Exit(m.Run())
diff --git a/runsc/test/image/ruby.rb b/runsc/test/image/ruby.rb
new file mode 100644
index 000000000..ae5de3419
--- /dev/null
+++ b/runsc/test/image/ruby.rb
@@ -0,0 +1,23 @@
+# Copyright 2018 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'sinatra'
+
+set :bind, "0.0.0.0"
+set :port, 8080
+
+get '/' do
+ 'Hello World'
+end
+
diff --git a/runsc/test/image/ruby.sh b/runsc/test/image/ruby.sh
new file mode 100644
index 000000000..54be2c931
--- /dev/null
+++ b/runsc/test/image/ruby.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright 2018 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+gem install sinatra
+ruby /src/ruby.rb