[POC][full-ci] Testing various oCIS env configurations (#6062)
* run api tests * run ocis via wrapper * add context, helpers and steps change ocis config * remove separate pipelines for special test cases * add context to behat config * fix suite name * set wrapper url while running tests * fix cors allow env name * address review * add ociswrapper codebase * add ci pipeline to build and cache wrapper * add step to check ociswrapper cache * invalidate wrapper cache and build new * build on pipeline step * undo unnecessary changes * undo unnecessary changes * fix php code * fix ocis run command * use tag for teardown * exclude wrapper vendor in codacy check * fix typos
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package config
|
||||
|
||||
var config = map[string]string{
|
||||
"port": "5000",
|
||||
}
|
||||
|
||||
func Get(key string) string {
|
||||
return config[key]
|
||||
}
|
||||
|
||||
func Set(key string, value string) {
|
||||
config[key] = value
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"ociswrapper/ocis"
|
||||
)
|
||||
|
||||
func parseJsonBody(reqBody io.ReadCloser) (map[string]any, error) {
|
||||
body, _ := io.ReadAll(reqBody)
|
||||
|
||||
if len(body) == 0 || !json.Valid(body) {
|
||||
return nil, errors.New("Invalid json data")
|
||||
}
|
||||
|
||||
var bodyMap map[string]any
|
||||
json.Unmarshal(body, &bodyMap)
|
||||
|
||||
return bodyMap, nil
|
||||
}
|
||||
|
||||
func sendResponse(res http.ResponseWriter, ocisStatus bool) {
|
||||
resBody := make(map[string]string)
|
||||
|
||||
if ocisStatus {
|
||||
res.WriteHeader(http.StatusOK)
|
||||
resBody["status"] = "OK"
|
||||
resBody["message"] = "oCIS server is running"
|
||||
} else {
|
||||
res.WriteHeader(http.StatusInternalServerError)
|
||||
resBody["status"] = "ERROR"
|
||||
resBody["message"] = "oCIS server error"
|
||||
}
|
||||
res.Header().Set("Content-Type", "application/json")
|
||||
|
||||
jsonResponse, _ := json.Marshal(resBody)
|
||||
res.Write(jsonResponse)
|
||||
}
|
||||
|
||||
func SetEnvHandler(res http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodPut {
|
||||
http.Error(res, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
environments, err := parseJsonBody(req.Body)
|
||||
if err != nil {
|
||||
http.Error(res, "Bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ocisStatus := ocis.Restart(environments)
|
||||
|
||||
sendResponse(res, ocisStatus)
|
||||
}
|
||||
|
||||
func RollbackHandler(res http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodDelete {
|
||||
http.Error(res, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
ocisStatus := ocis.Restart(nil)
|
||||
|
||||
sendResponse(res, ocisStatus)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"ociswrapper/common"
|
||||
"ociswrapper/ocis/config"
|
||||
"ociswrapper/wrapper/handlers"
|
||||
)
|
||||
|
||||
func Start(port string) {
|
||||
defer common.Wg.Done()
|
||||
|
||||
if port == "" {
|
||||
port = config.Get("port")
|
||||
}
|
||||
|
||||
httpServer := &http.Server{
|
||||
Addr: ":" + port,
|
||||
}
|
||||
|
||||
var mux = http.NewServeMux()
|
||||
mux.HandleFunc("/", http.NotFound)
|
||||
mux.HandleFunc("/config", handlers.SetEnvHandler)
|
||||
mux.HandleFunc("/rollback", handlers.RollbackHandler)
|
||||
|
||||
httpServer.Handler = mux
|
||||
|
||||
log.Printf("Starting server on port %s...", port)
|
||||
|
||||
err := httpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user