diff --git a/.gitignore b/.gitignore index 95ea8961e..23a826675 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ ~/.* *.test tests/assets/dorifi/dorifi +tests/assets/multi-process/dorifi diff --git a/Makefile b/Makefile index fa96bf811..66e95afb1 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,7 @@ test-smoke: build-dorifi build-dorifi: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C tests/assets/golang -o ../dorifi/dorifi . + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C tests/assets/golang -o ../multi-process/dorifi . GOFUMPT = $(shell go env GOPATH)/bin/gofumpt install-gofumpt: diff --git a/tests/assets/golang/main.go b/tests/assets/golang/main.go index 96f17c360..73907f76b 100644 --- a/tests/assets/golang/main.go +++ b/tests/assets/golang/main.go @@ -8,12 +8,26 @@ import ( "path/filepath" "strconv" "strings" + "time" ) const ServiceBindingRootEnv = "SERVICE_BINDING_ROOT" func main() { - http.HandleFunc("/", helloWorldHandler) + arg := "" + if len(os.Args) > 1 { + arg = os.Args[1] + } + + if arg != "" && arg != "web" { + for range time.Tick(time.Second * 1) { + fmt.Printf("Hello from %q\n", arg) + } + + return + } + + http.HandleFunc("/", helloWorldHandler(arg)) http.HandleFunc("/env.json", envJsonHandler) http.HandleFunc("/servicebindingroot", serviceBindingRootHandler) http.HandleFunc("/servicebindings", serviceBindingsHandler) @@ -50,8 +64,14 @@ func exitHandler(w http.ResponseWriter, r *http.Request) { os.Exit(exitCode) } -func helloWorldHandler(w http.ResponseWriter, _ *http.Request) { - fmt.Fprintln(w, "Hi, I'm Dorifi!") +func helloWorldHandler(arg string) func(w http.ResponseWriter, _ *http.Request) { + return func(w http.ResponseWriter, _ *http.Request) { + if arg == "" { + fmt.Fprintln(w, "Hi, I'm Dorifi!") + } else { + fmt.Fprintf(w, "Hi, I'm Dorifi (%s)!\n", arg) + } + } } func envJsonHandler(w http.ResponseWriter, _ *http.Request) { diff --git a/tests/assets/multi-process/Procfile b/tests/assets/multi-process/Procfile index 660639d98..df2f8db62 100644 --- a/tests/assets/multi-process/Procfile +++ b/tests/assets/multi-process/Procfile @@ -1,2 +1,2 @@ -web: node server.js -worker: node server.js worker +web: ./dorifi web +worker: ./dorifi worker diff --git a/tests/assets/multi-process/package.json b/tests/assets/multi-process/package.json deleted file mode 100644 index 2db5f6673..000000000 --- a/tests/assets/multi-process/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name" : "multi-process", - "version": "1.0.0", - "description": "Multi process sample app for Korifi" -} diff --git a/tests/assets/multi-process/server.js b/tests/assets/multi-process/server.js deleted file mode 100644 index a61d12ddb..000000000 --- a/tests/assets/multi-process/server.js +++ /dev/null @@ -1,27 +0,0 @@ -var http = require('http'); -var url = require('url'); - -HOST = null; - -var host = "0.0.0.0"; -var port = process.env.PORT || 3000; - -function logger() { - console.log('Console output from worker process in multi-process'); -} - -switch (process.argv[process.argv.length - 1]) { - case 'worker': - setInterval(logger, 1000); - break; - default: - http.createServer(function (req, res) { - res.writeHead(200, {'Content-Type': 'text/html'}); - res.write('