diff --git a/cnf-certification-test/webserver/index.html b/cnf-certification-test/webserver/index.html index 07611612a..d878b7dc0 100644 --- a/cnf-certification-test/webserver/index.html +++ b/cnf-certification-test/webserver/index.html @@ -1,5 +1,6 @@ + @@ -9,6 +10,9 @@ sizes="any" href="https://ux.redhat.com/assets/logo-red-hat.svg"> + + + + - + +
Red Hat

CNF Certification Test

-
@@ -165,19 +195,81 @@

CNF Certification Test

required type="file"> - -
+ Upload TNF Configuration File: + +
+
TNF Configuration - - - + Add NameSpace + Remove NameSpace +
- + Add podsUnderTestLabels
+ Remove podsUnderTestLabels + +
+ + Add operatorsUnderTestLabels
+ Remove operatorsUnderTestLabels + + + Add targetCrdFilters
+ Remove targetCrdFilters + + + Add managedDeployments
+ Remove managedDeployments + + + + Add managedStatefulsets
+ Remove managedStatefulsets + + + Add acceptedKernelTaints
+ Remove acceptedKernelTaints + + + Add skipHelmChartList
+ Remove skipHelmChartList + + + + Add skipScalingTestDeployments
+ Remove skipScalingTestDeployments + + + Add skipScalingTestStatefulsets
+ Remove skipScalingTestStatefulsets + + + Add servicesignorelist
+ Remove servicesignorelist + + + + + + + + + + + + Add ValidProtocolNames
+ Remove ValidProtocolNames + + + +
+
Select a Test @@ -185,17 +277,36 @@

CNF Certification Test

Lifecycle + Manageability + +
Run Certification Test diff --git a/cnf-certification-test/webserver/submit.js b/cnf-certification-test/webserver/submit.js index e06d0aab9..3834401d4 100644 --- a/cnf-certification-test/webserver/submit.js +++ b/cnf-certification-test/webserver/submit.js @@ -2,15 +2,40 @@ export async function submit(form) { form.elements.submit.disabled = true; const formdata = new FormData(form); + // Iterate over form elements and add those with non-empty values to FormData + Array.from(form.elements).forEach(element => { + if ( element.hasAttribute('value') && element.type!="checkbox") { + console.log(element) + console.log(element.value) + console.log((element.id.match(/[a-zA-Z]/g) || []).join('')) + formdata.append((element.id.match(/[a-zA-Z]/g) || []).join(''), element.value); + } + }); + console.log(JSON.stringify(Object.fromEntries(formdata))) for (const el of form.elements) if (el instanceof HTMLFieldSetElement) el.disabled = true - + console.log(Array.from(formdata.entries())); + // Collect data from form fields - const fields = Array.from(formdata.entries()).reduce((acc, [key, val]) => ({ ...acc, - [key]: key in acc ? [acc[key], val] : val - }), {}); + const fields = Array.from(formdata.entries()).reduce((acc, [key, val]) => { + console.log(acc[key]); + console.log(val); + + if (acc[key] === undefined) { + // If the key is not in the accumulator, set it to the value or an array with the value + acc[key] = [val]; + } else if (Array.isArray(acc[key])) { + // If the key is already an array, push the new value to the array + acc[key].push(val); + } else { + // If the key is a single value, convert it to an array with both values + acc[key] = [acc[key], val]; + } + return acc; + }, {}); delete fields.submit; console.log(fields); + console.log(formdata) formdata.append("jsonData", JSON.stringify(fields)); // Send an HTTP request to the server to run the function diff --git a/cnf-certification-test/webserver/webserver.go b/cnf-certification-test/webserver/webserver.go index 5689f8b2c..b575d0508 100644 --- a/cnf-certification-test/webserver/webserver.go +++ b/cnf-certification-test/webserver/webserver.go @@ -22,7 +22,7 @@ import ( "github.com/test-network-function/cnf-certification-test/pkg/certsuite" "github.com/test-network-function/cnf-certification-test/pkg/configuration" "github.com/test-network-function/cnf-certification-test/pkg/provider" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" ) type webServerContextKey string @@ -46,6 +46,10 @@ var logs []byte //go:embed toast.js var toast []byte + +//go:embed index.js +var index []byte + var Buf *bytes.Buffer var upgrader = websocket.Upgrader{ @@ -83,31 +87,32 @@ func logStreamHandler(w http.ResponseWriter, r *http.Request) { } type RequestedData struct { - SelectedOptions interface{} `json:"selectedOptions"` + SelectedOptions []string `json:"selectedOptions"` + TargetNameSpaces []string `json:"targetNameSpaces"` + PodsUnderTestLabels []string `json:"podsUnderTestLabels"` + OperatorsUnderTestLabels []string `json:"operatorsUnderTestLabels"` + ManagedDeployments []string `json:"managedDeployments"` + ManagedStatefulsets []string `json:"managedStatefulsets"` + SkipScalingTestDeploymentsnamespace []string `json:"skipScalingTestDeploymentsnamespace"` + SkipScalingTestDeploymentsname []string `json:"skipScalingTestDeploymentsname"` + SkipScalingTestStatefulsetsnamespace []string `json:"skipScalingTestStatefulsetsnamespace"` + SkipScalingTestStatefulsetsname []string `json:"skipScalingTestStatefulsetsname"` + TargetCrdFiltersnameSuffix []string `json:"targetCrdFiltersnameSuffix"` + TargetCrdFiltersscalable []string `json:"targetCrdFiltersscalable"` + AcceptedKernelTaints []string `json:"acceptedKernelTaints"` + SkipHelmChartList []string `json:"skipHelmChartList"` + Servicesignorelist []string `json:"servicesignorelist"` + ValidProtocolNames []string `json:"ValidProtocolNames"` + DebugDaemonSetNamespace []string `json:"DebugDaemonSetNamespace"` + CollectorAppEndPoint []string `json:"CollectorAppEndPoint"` + ExecutedBy []string `json:"executedBy"` + CollectorAppPassword []string `json:"CollectorAppPassword"` + PartnerName []string `json:"PartnerName"` } type ResponseData struct { Message string `json:"message"` } -func FlattenData(data interface{}, result []string) []string { - switch v := data.(type) { - case string: - result = append(result, v) - case []interface{}: - for _, item := range v { - result = FlattenData(item, result) - } - case map[string]interface{}: - for key, item := range v { - if key == "selectedOptions" { - result = FlattenData(item, result) - } - result = FlattenData(item, result) - } - } - return result -} - func installReqHandlers() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // Set the content type to "text/html". @@ -152,6 +157,18 @@ func installReqHandlers() { return } }) + + http.HandleFunc("/index.js", func(w http.ResponseWriter, r *http.Request) { + // Set the content type to "application/javascript". + w.Header().Set("Content-Type", "application/javascript") + // Write the embedded JavaScript content to the response. + _, err := w.Write(index) + if err != nil { + http.Error(w, "Failed to write response", http.StatusInternalServerError) + return + } + }) + // Serve the static HTML file http.HandleFunc("/logstream", logStreamHandler) }