Skip to content

Commit

Permalink
making strema dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
aldrinjenson committed Oct 16, 2023
1 parent 1a4ba2d commit 4ab43fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 46 deletions.
57 changes: 15 additions & 42 deletions modules_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,11 @@ package main

import (
"bytes"
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func generateModuleRegistrationJSON(username, password, address string) string {
return fmt.Sprintf(`{
"version": "v0.0.2",
"username": "%s",
"password": "%s",
"url": "%s",
"streamConfig": {
"path": "/api/v1/logstream/{stream_name}/config"
},
"routes": [
{
"serverPath": "anomaly",
"modulePath": "/api/v1/anomaly",
"method": "GET"
},
{
"serverPath": "models",
"modulePath": "/api/v1/models",
"method": "GET"
}
]
}`, username, password, address)
}

const sample_module_config_per_stream = `
[{
"mode": "col",
Expand All @@ -59,30 +34,22 @@ const sample_module_config_per_stream = `
}]
`

const sample_proxy_route_body = `
{
"stream_name": "demo"
}
`

func test_module_registration_flow(t *testing.T) error {

sampleModuleRegistrationJSON := generateModuleRegistrationJSON(NewGlob.Username, NewGlob.PanoramaBaseAddress, NewGlob.PanoramaBaseAddress)
module_name := "panorama" // Remove the "const" keyword
stream_name := NewGlob.Stream

module_name := "random_module"
stream_name := "demo"
sample_proxy_route_body := `
{
"stream_name": "` + stream_name + `"
}
`

println("Module Registration flow for: " + module_name)

println("Testing Registering Module")
req, _ := NewGlob.Client.NewRequest("PUT", "modules/"+module_name, bytes.NewBufferString(sampleModuleRegistrationJSON))
response, err := NewGlob.Client.Do(req)
require.NoErrorf(t, err, "Request failed: %s", err)
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body))

println("Getting list of modules:")
req, _ = NewGlob.Client.NewRequest("GET", "modules", bytes.NewBufferString("{}"))
response, err = NewGlob.Client.Do(req)
req, _ := NewGlob.Client.NewRequest("GET", "modules", bytes.NewBufferString("{}"))
response, err := NewGlob.Client.Do(req)
require.NoErrorf(t, err, "Request failed: %s", err)
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body))

Expand All @@ -105,6 +72,12 @@ func test_module_registration_flow(t *testing.T) error {
require.NoErrorf(t, err, "Request failed: %s", err)
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body))

println("Stop anomaly watching by putting config as empty")
req, _ = NewGlob.Client.NewRequest("PUT", "modules/"+module_name+"/config/"+stream_name, bytes.NewBufferString("{}"))
response, err = NewGlob.Client.Do(req)
require.NoErrorf(t, err, "Request failed: %s", err)
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body))

println("Testing DeRegistering Module")
req, _ = NewGlob.Client.NewRequest("DELETE", "modules/"+module_name, bytes.NewBufferString("{}"))
response, err = NewGlob.Client.Do(req)
Expand Down
8 changes: 4 additions & 4 deletions quest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ func TestSmokeCreateStream(t *testing.T) {
CreateStream(t, NewGlob.Client, NewGlob.Stream)
}

func TestSmokeModulesAPI(t *testing.T) {
test_module_registration_flow(t)
}

func TestSmokeIngestEventsToStream(t *testing.T) {
cmd := exec.Command("flog", "-f", "json", "-n", "50")
var out strings.Builder
Expand Down Expand Up @@ -229,6 +225,10 @@ func TestLoadStreamNoBatchWithK6(t *testing.T) {
}
}

func TestSmokeModulesAPI(t *testing.T) {
test_module_registration_flow(t)
}

func TestDeleteStream(t *testing.T) {
DeleteStream(t, NewGlob.Client, NewGlob.Stream)
}

0 comments on commit 4ab43fa

Please sign in to comment.