Add a hello world docker image test for rust runtime.

PiperOrigin-RevId: 603161919
This commit is contained in:
Jing Chen
2024-01-31 14:38:10 -08:00
committed by gVisor bot
parent 94f3d8a792
commit a5f0778c38
4 changed files with 41 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "hello-world"
version = "0.1.0"
[[bin]]
name = "hello-world"
path = "helloworld.rs"
+12
View File
@@ -0,0 +1,12 @@
FROM rust:1.75.0
# Set the working directory
WORKDIR /app
# Copy the application files into the image
COPY Cargo.toml helloworld.rs ./
# Build the application in release mode
RUN cargo build --release
# Set the command to run the binary
CMD ["./target/release/hello-world"]
+3
View File
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, World!");
}
+19
View File
@@ -64,6 +64,25 @@ func TestHelloWorld(t *testing.T) {
}
}
func TestRust(t *testing.T) {
ctx := context.Background()
d := dockerutil.MakeContainer(ctx, t)
defer d.CleanUp(ctx)
// Run the basic container.
out, err := d.Run(ctx, dockerutil.RunOpts{
Image: "basic/rust",
})
if err != nil {
t.Fatalf("docker run failed: %v", err)
}
// Check the output.
if !strings.Contains(out, "Hello, World!") {
t.Fatalf("Container didn't say Hello, World!: got %s", out)
}
}
func runHTTPRequest(ip string, port int) error {
url := fmt.Sprintf("http://%s:%d/not-found", ip, port)
resp, err := http.Get(url)