Skip to content

Commit

Permalink
smoke: support more images in container
Browse files Browse the repository at this point in the history
Support: python, golang, ruby, amazoncorretto.

Signed-off-by: Yadong Ding <[email protected]>
  • Loading branch information
Desiki-high authored and imeoer committed Dec 4, 2023
1 parent eeddfff commit ba8d310
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
2 changes: 2 additions & 0 deletions smoke/tests/texture/golang/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd /src
go run main.go
7 changes: 7 additions & 0 deletions smoke/tests/texture/golang/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("hello")
}
5 changes: 5 additions & 0 deletions smoke/tests/texture/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Main {
public static void main(String[] args) {
System.out.println("hello");
}
}
3 changes: 3 additions & 0 deletions smoke/tests/texture/java/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd /src
javac Main.java
java Main
1 change: 1 addition & 0 deletions smoke/tests/texture/python/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python -c 'print("hello")'
1 change: 1 addition & 0 deletions smoke/tests/texture/ruby/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby -e "puts \"hello\""
51 changes: 48 additions & 3 deletions smoke/tests/tool/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,41 @@ var URL_WAIT = map[string]RunArgs{
},
}

var CMD_STDOUT = map[string]RunArgs{
"golang": {
Mount: mountPath{
source: "tests/texture/golang",
target: "/src",
},
},
"amazoncorretto": {
Mount: mountPath{
source: "tests/texture/java",
target: "/src",
},
},
"ruby": {
Mount: mountPath{
source: "tests/texture/ruby",
target: "/src",
},
},
"python": {
Mount: mountPath{
source: "tests/texture/python",
target: "/src",
},
},
}

// SupportContainerImage help to check if we support the image or not
func SupportContainerImage(image string) bool {
_, ok := URL_WAIT[image]
return ok
_, existsInUrlWait := URL_WAIT[image]
_, existsInCmdStdout := CMD_STDOUT[image]
return existsInUrlWait || existsInCmdStdout
}

// runUrlWaitContainer run Contaienr util geting http response from WaitUrl
// runUrlWaitContainer run container util geting http response from WaitUrl
func runUrlWaitContainer(t *testing.T, image string, containerName string, runArgs RunArgs) {
cmd := "sudo nerdctl --insecure-registry --snapshotter nydus run -d --net=host"
if runArgs.Mount.source != "" {
Expand All @@ -91,6 +119,20 @@ func runUrlWaitContainer(t *testing.T, image string, containerName string, runAr
}
}

// runCmdStdoutContainer run some commands in container by entrypoint.sh
func runCmdStdoutContainer(t *testing.T, image string, containerName string, runArgs RunArgs) {
cmd := "sudo nerdctl --insecure-registry --snapshotter nydus run -i --net=host"
if runArgs.Mount.source != "" {
currentDir, err := os.Getwd()
if err != nil {
t.Fatalf("can't get rooted path name")
}
cmd += fmt.Sprintf(" -v %s:%s", filepath.Join(currentDir, runArgs.Mount.source), runArgs.Mount.target)
}
cmd += fmt.Sprintf(" --name=%s %s sh /src/entrypoint.sh", containerName, image)
Run(t, cmd)
}

// RunContainerWithBaseline and get metrics from api socket.
// Test will fail if performance below baseline.
func RunContainerWithBaseline(t *testing.T, image string, containerName string, mode string) {
Expand Down Expand Up @@ -122,6 +164,9 @@ func RunContainer(t *testing.T, image string, containerName string) *ContainerMe
if ok {
runUrlWaitContainer(t, image, containerName, args)
defer clearContainer(t, image, containerName)
} else if args, ok := CMD_STDOUT[ImageRepo(t, image)]; ok {
runCmdStdoutContainer(t, image, containerName, args)
defer clearContainer(t, image, containerName)
}

containerMetic.E2ETime = time.Since(startTime)
Expand Down

0 comments on commit ba8d310

Please sign in to comment.