-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E tests for different languages (#917)
1. go 2. nginx_1.15.6 3. node_v11.5.0 4. php_7.3.5 5. python_3.6.7 6. ruby_2.5.1 7. rust
- Loading branch information
1 parent
b7cb529
commit 8948d92
Showing
20 changed files
with
355 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Go parameters | ||
GOBUILD= $(GO) build | ||
GOCLEAN= $(GO) clean | ||
GOTEST= $(GO) test | ||
GOGET= $(GO) get | ||
BINARY_NAME= ops | ||
|
||
test: | ||
$(GOTEST) -v | ||
|
||
.PHONY: test | ||
|
||
include ../../rules.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
"testing" | ||
"time" | ||
) | ||
|
||
// AsyncCmdStart runs cmd with asynchronously and returns *exec.Cmd, stdout/stderr as one or err if something blew up | ||
func AsyncCmdStart(cmd string) (command *exec.Cmd, buffer *bytes.Buffer, err error) { | ||
command = exec.Command("/bin/bash", "-c", cmd) | ||
buffer = &bytes.Buffer{} | ||
command.Stdout = buffer | ||
command.Stderr = buffer | ||
command.SysProcAttr = &syscall.SysProcAttr{} | ||
command.SysProcAttr.Setsid = true | ||
err = command.Start() | ||
if err != nil { | ||
return command, buffer, err | ||
} | ||
return command, buffer, nil | ||
} | ||
|
||
func KillProcess(command *exec.Cmd) { | ||
pgid, err := syscall.Getpgid(command.Process.Pid) | ||
if err == nil { | ||
syscall.Kill(-pgid, syscall.SIGKILL) | ||
} | ||
command.Wait() | ||
} | ||
|
||
func goPrebuild(t *testing.T) { | ||
effect, err := exec.Command("/bin/bash", "-c", "go build main.go").CombinedOutput() | ||
if err != nil { | ||
t.Log(effect) | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func rubyPrebuild(t *testing.T) { | ||
effect, err := exec.Command("/bin/bash", "-c", "mkdir -p .ruby && export GEM_HOME=.ruby && gem install sinatra --no-rdoc --no-ri").CombinedOutput() | ||
if err != nil { | ||
t.Log(effect) | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func rustPrebuild(t *testing.T) { | ||
effect, err := exec.Command("/bin/bash", "-c", "rustc http_server.rs -o main").CombinedOutput() | ||
if err != nil { | ||
t.Log(effect) | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func testPackages(t *testing.T) { | ||
var tests = []struct { | ||
name string | ||
pkg string | ||
dir string | ||
request string | ||
elf string | ||
prebuild func(t *testing.T) | ||
}{ | ||
{name: "python_3.6.7", pkg: "python_3.6.7", dir: "python_3.6.7", request: "http://0.0.0.0:8000"}, | ||
{name: "node_v11.5.0", pkg: "node_v11.5.0", dir: "node_v11.5.0", request: "http://0.0.0.0:8083"}, | ||
{name: "nginx_1.15.6", pkg: "nginx_1.15.6", dir: "nginx_1.15.6", request: "http://0.0.0.0:8084"}, | ||
{name: "php_7.3.5", pkg: "php_7.3.5", dir: "php_7.3.5", request: "http://0.0.0.0:9501"}, | ||
{name: "ruby_2.5.1", pkg: "ruby_2.5.1", dir: "ruby_2.5.1", request: "http://0.0.0.0:4567", prebuild: rubyPrebuild}, | ||
{name: "go", dir: "go", request: "http://0.0.0.0:8080", elf: "main", prebuild: goPrebuild}, | ||
{name: "rust", dir: "rust", request: "http://0.0.0.0:8080", elf: "main", prebuild: rustPrebuild}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var execcmd string | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Chdir(dir) | ||
err = os.Chdir(dir + "/" + tt.dir) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if tt.prebuild != nil { | ||
t.Log("Calling prebuild", tt.name) | ||
tt.prebuild(t) | ||
} | ||
if tt.elf != "" { | ||
execcmd = fmt.Sprintf("ops run %s -c config.json", tt.elf) | ||
} else { | ||
execcmd = fmt.Sprintf("ops load %s -c config.json", tt.pkg) | ||
} | ||
p, buffer, err := AsyncCmdStart(execcmd) | ||
defer KillProcess(p) | ||
if err != nil { | ||
t.Logf("Output: %v", buffer) | ||
t.Fatal(err) | ||
} | ||
time.Sleep(time.Second * 10) | ||
for count := 0; count <= 5; count++ { | ||
resp, err := http.Get(tt.request) | ||
if err != nil { | ||
t.Logf("Output: %v", buffer) | ||
t.Fatal(err) | ||
} | ||
t.Log("Status code", resp.StatusCode) | ||
if resp.StatusCode != 200 { | ||
t.Logf("Output: %v", buffer) | ||
t.Fatalf("Expected 200 but got %v", resp.StatusCode) | ||
} | ||
if resp.ContentLength == 0 { | ||
t.Logf("Output: %v", buffer) | ||
t.Fatalf("Received empty content") | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// RunE2ETests runs all end to end tests | ||
func RunE2ETests(t *testing.T) { | ||
t.Log("Running E2E test") | ||
t.Run("packages", testPackages) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package e2e | ||
|
||
import "testing" | ||
|
||
func TestE2E(t *testing.T) { | ||
RunE2ETests(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Args": ["main"], | ||
"RunConfig": { | ||
"Ports": [8080] | ||
}, | ||
"Boot": "../../../output/boot/boot.img", | ||
"Kernel": "../../../output/stage3/bin/stage3.img", | ||
"Mkfs": "../../../output/mkfs/bin/mkfs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path) | ||
}) | ||
|
||
http.ListenAndServe(":8080", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Files": ["index.html"], | ||
"Dirs": ["usr"], | ||
"RunConfig": { | ||
"Ports": [8084] | ||
}, | ||
"Boot": "../../../output/boot/boot.img", | ||
"Kernel": "../../../output/stage3/bin/stage3.img", | ||
"Mkfs": "../../../output/mkfs/bin/mkfs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
worker_processes 1; | ||
daemon off; | ||
master_process off; | ||
|
||
pid bob.pid; | ||
|
||
error_log stderr crit; | ||
|
||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
|
||
access_log off; | ||
error_log off; | ||
|
||
|
||
server { | ||
listen 8084; | ||
|
||
location / { | ||
root /; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Args": ["hi.js"], | ||
"RunConfig": { | ||
"Ports": [8083] | ||
}, | ||
"Boot": "../../../output/boot/boot.img", | ||
"Kernel": "../../../output/stage3/bin/stage3.img", | ||
"Mkfs": "../../../output/mkfs/bin/mkfs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var http = require('http'); | ||
http.createServer(function (req, res) { | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
res.end('Hello World\n'); | ||
}).listen(8083, "0.0.0.0"); | ||
console.log('Server running at http://127.0.0.1:8083/'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
$http = new swoole_http_server("0.0.0.0", 9501, SWOOLE_BASE); | ||
$http->on("start", function ($server) { | ||
echo "Swoole http server is started at http://127.0.0.1:9501\n"; | ||
}); | ||
$http->on("request", function ($request, $response) { | ||
$response->header("Content-Type", "text/plain"); | ||
$response->end("Hello World\n"); | ||
}); | ||
$http->start(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Args": ["b.php"], | ||
"RunConfig": { | ||
"Ports": [9501] | ||
}, | ||
"Boot": "../../../output/boot/boot.img", | ||
"Kernel": "../../../output/stage3/bin/stage3.img", | ||
"Mkfs": "../../../output/mkfs/bin/mkfs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Args":["-m", "http.server"], | ||
"RunConfig": { | ||
"Ports": [8000] | ||
}, | ||
"Boot": "../../../output/boot/boot.img", | ||
"Kernel": "../../../output/stage3/bin/stage3.img", | ||
"Mkfs": "../../../output/mkfs/bin/mkfs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"Args": ["myapp.rb", "-o", "0.0.0.0"], | ||
"Dirs": [".ruby"], | ||
"ENV": { | ||
"GEM_HOME": ".ruby" | ||
}, | ||
"RunConfig": { | ||
"Ports": [4567] | ||
}, | ||
"Boot": "../../../output/boot/boot.img", | ||
"Kernel": "../../../output/stage3/bin/stage3.img", | ||
"Mkfs": "../../../output/mkfs/bin/mkfs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'sinatra' | ||
|
||
get '/' do | ||
'Hello World!' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Args": ["main"], | ||
"RunConfig": { | ||
"Ports": [8080] | ||
}, | ||
"Boot": "../../../output/boot/boot.img", | ||
"Kernel": "../../../output/stage3/bin/stage3.img", | ||
"Mkfs": "../../../output/mkfs/bin/mkfs" | ||
} |
Oops, something went wrong.