diff options
author | Fabricio Voznika <fvoznika@google.com> | 2018-09-28 15:51:36 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-09-28 15:52:33 -0700 |
commit | 49ff81a42b51a3fa2ee139e1e86179fa0c427a86 (patch) | |
tree | 35194b1301a589cf5ff830f84f8b7c984f88f0a5 /runsc/test/image/image_test.go | |
parent | 2496d9b4b6343154525f73e9583a4a60bebcfa30 (diff) |
Add ruby image tests
PiperOrigin-RevId: 215009066
Change-Id: I54ab920fa649cf4d0817f7cb8ea76f9126523330
Diffstat (limited to 'runsc/test/image/image_test.go')
-rw-r--r-- | runsc/test/image/image_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
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()) |