-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
189 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,45 @@ | ||
import { check } from 'k6'; | ||
import { Http, Tracetest } from "k6/x/tracetest"; | ||
import { sleep } from "k6"; | ||
|
||
export const options = { | ||
vus: 1, | ||
duration: "5s", | ||
duration: "6s", | ||
}; | ||
|
||
const http = new Http(); | ||
const tracetest = Tracetest({ | ||
serverUrl: "http://localhost:3000", | ||
}); | ||
const testId = "J0d887oVR"; | ||
const testId = "kc_MgKoVR"; | ||
const pokemonId = 6; | ||
const http = new Http(); | ||
|
||
export default function () { | ||
/// successful test run | ||
http.get("http://localhost:8081/pokemon?take=5", { | ||
const url = "http://localhost:8081/pokemon/import"; | ||
const payload = JSON.stringify({ | ||
id: pokemonId, | ||
}); | ||
const params = { | ||
tracetest: { | ||
testId, | ||
}, | ||
}); | ||
|
||
/// failed test specs test run | ||
http.get("http://localhost:8081/pokemon?take=10", { | ||
tracetest: { | ||
testId: "nDdBCnoVg", | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
/// not existing test | ||
// http.get("http://localhost:8081/pokemon?take=10", { | ||
// tracetest: { | ||
// testId: "doesnt-exist", | ||
// }, | ||
// }); | ||
}; | ||
|
||
/// wrong endpoint | ||
// http.get("http://localhost:8081/wrong", { | ||
// tracetest: { | ||
// testId: "nDdBCnoVg", | ||
// }, | ||
// }); | ||
const response = http.post(url, payload, params); | ||
|
||
check(response, { | ||
'is status 200': (r) => r.status === 200, | ||
'body matches de id': (r) => JSON.parse(r.body).id === pokemonId, | ||
}); | ||
sleep(1); | ||
} | ||
|
||
export function handleSummary() { | ||
return { | ||
stdout: tracetest.summary(), | ||
'tracetest.json': tracetest.json(), | ||
}; | ||
} | ||
// export function handleSummary() { | ||
// return { | ||
// stdout: tracetest.summary(), | ||
// "tracetest.json": tracetest.json(), | ||
// }; | ||
// } |
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,58 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/dop251/goja" | ||
"github.com/kubeshop/xk6-tracetest/utils" | ||
"go.k6.io/k6/js/modules" | ||
) | ||
|
||
var defaultPropagatorList = []PropagatorName{ | ||
TraceContext, | ||
Baggage, | ||
PropagatorB3, | ||
OT, | ||
Jaeger, | ||
XRay, | ||
} | ||
|
||
type HttpClientOptions struct { | ||
Propagator Propagator | ||
Tracetest TracetestOptions | ||
} | ||
|
||
func NewHttpClientOptions(vu modules.VU, val goja.Value) (HttpClientOptions, error) { | ||
rawOptions := utils.ParseOptions(vu, val) | ||
options := HttpClientOptions{ | ||
Propagator: NewPropagator(defaultPropagatorList), | ||
Tracetest: TracetestOptions{ | ||
ShouldWait: true, | ||
VariableName: "TRACE_ID", | ||
}, | ||
} | ||
|
||
if len(rawOptions) == 0 { | ||
return options, nil | ||
} | ||
|
||
for key, value := range rawOptions { | ||
switch key { | ||
case "propagator": | ||
rawPropagatorList := strings.Split(value.ToString().String(), ",") | ||
propagatorList := make([]PropagatorName, len(rawPropagatorList)) | ||
for i, propagator := range rawPropagatorList { | ||
propagatorList[i] = PropagatorName(propagator) | ||
} | ||
|
||
options.Propagator = NewPropagator(propagatorList) | ||
case "tracetest": | ||
options.Tracetest = NewTracetestOptions(vu.Runtime(), val.ToObject(vu.Runtime())) | ||
default: | ||
return options, fmt.Errorf("unknown HTTP tracing option '%s'", key) | ||
} | ||
} | ||
|
||
return options, 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
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,35 @@ | ||
package models | ||
|
||
import "github.com/dop251/goja" | ||
|
||
type TracetestOptions struct { | ||
TestID string | ||
ShouldWait bool | ||
VariableName string | ||
} | ||
|
||
func NewTracetestOptions(runTime *goja.Runtime, params *goja.Object) TracetestOptions { | ||
rawOptions := params.Get("tracetest") | ||
options := TracetestOptions{ | ||
ShouldWait: true, | ||
VariableName: "TRACE_ID", | ||
} | ||
|
||
if rawOptions == nil { | ||
return options | ||
} | ||
|
||
optionsObject := rawOptions.ToObject(runTime) | ||
for _, key := range optionsObject.Keys() { | ||
switch key { | ||
case "testId": | ||
options.TestID = optionsObject.Get(key).String() | ||
case "shouldWait": | ||
options.ShouldWait = optionsObject.Get(key).ToBoolean() | ||
case "variableName": | ||
options.VariableName = optionsObject.Get(key).ToString().String() | ||
} | ||
} | ||
|
||
return options | ||
} |
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
Oops, something went wrong.