Skip to content

Commit

Permalink
chore: run tests in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 29, 2023
1 parent c86f55b commit 0141359
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 13 deletions.
51 changes: 51 additions & 0 deletions template_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gomplate_test

import (
"testing"

"github.com/flanksource/gomplate/v3"
)

// var x = map[string]any {
// "sslAge": 7010490606167092,
// "json": map[string]any{},
// "content": "",
// "headers": map[string]interface {} ["Content-Type": *(*interface {})(0xc01d21a508),
// "Content-Length": *(*interface {})(0xc01d21a518),
// "Access-Control-Allow-Origin": *(*interface {})(0xc01d21a528),
// "Access-Control-Allow-Credentials": *(*interface {})(0xc01d21a538),
// "Strict-Transport-Security": *(*interface {})(0xc01d21a548),
// "Date": *(*interface {})(0xc01d21a558),
// },
// "canary": map[string]interface {} ["name": *(*interface {})(0xc01d21a1a8), "namespace": *(*interface {})(0xc01d21a1b8), "labels": *(*interface {})(0xc01d21a1c8), "id": *(*interface {})(0xc01d21a1d8), ],
// "check": 7010490606167092,
// "duration": 702,
// "results": map[string]any{"code": 200, "elapsed": 702296127}

func TestMa(t *testing.T) {
env := map[string]any{
"code": "200",
"sslAge": "true",
"check": map[string]any{
"name": "http-expr-tests",
"id": "018c0096-81c2-7e7d-b324-157d2172c547",
"description": "",
"labels": map[string]any{},
"endpoint": "https://httpbin.demo.aws.flanksource.com/status/200",
},
"duration": 702,
"results": map[string]any{"code": 200, "elapsed": 702296127},
}

for i := 0; i < 10000; i++ {
_, err := gomplate.RunTemplate(env, gomplate.Template{Expression: `string(code) + " should be 500"`})
if err != nil {
t.Fatal(err)
}

if _, ok := env["check"].(map[string]any); !ok {
t.Logf("Of type %T", env["check"])
t.Fail()
}
}
}
77 changes: 64 additions & 13 deletions tests/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

func Test_serialize(t *testing.T) {
t.Parallel()

tests := []struct {
name string
in map[string]any
Expand Down Expand Up @@ -160,32 +162,81 @@ func Test_serialize(t *testing.T) {
{
name: "canary checker ctx.Environment",
in: map[string]any{
"r": &Address{
City: "Bhaktapur",
"canary": map[string]any{
"id": "3ac56bb3-fbf6-4479-bf3b-5f2758e9fdbe",
"labels": map[string]string{
"Expected-Fail": "true",
"kustomize.toolkit.fluxcd.io/name": "canaries",
"kustomize.toolkit.fluxcd.io/namespace": "default",
},
"name": "http-fail",
"namespace": "canaries",
},
"check": map[string]any{
"name": "custom-check",
"meta": map[string]any{
"key": "value",
},
"description": "",
"endpoint": "",
"id": "018c0096-7342-6f80-5ea5-6df245079b7a",
"labels": map[string]string(nil),
"name": "http fail test expr check",
},
"code": 200,
"content": "",
"duration": 681,
"elapsed": 681153615,
"headers": map[string]string{
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Origin": "*",
"Content-Length": "0",
"Content-Type": "text/html; charset=utf-8",
"Date": "Wed,29 Nov 2023 06:19:30 GMT",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
},
"json": map[string]any{},
"results": map[string]any{},
"sslAge": 7004023369313149,
},
want: map[string]any{
"r": map[string]any{
"city_name": "Bhaktapur",
"canary": map[string]any{
"id": "3ac56bb3-fbf6-4479-bf3b-5f2758e9fdbe",
"labels": map[string]any{
"Expected-Fail": "true",
"kustomize.toolkit.fluxcd.io/name": "canaries",
"kustomize.toolkit.fluxcd.io/namespace": "default",
},
"name": "http-fail",
"namespace": "canaries",
},
"check": map[string]any{
"name": "custom-check",
"meta": map[string]any{
"key": "value",
},
"description": "",
"endpoint": "",
"id": "018c0096-7342-6f80-5ea5-6df245079b7a",
"labels": map[string]any{},
"name": "http fail test expr check",
},
"code": int64(200),
"content": "",
"duration": int64(681),
"elapsed": int64(681153615),
"headers": map[string]any{
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Origin": "*",
"Content-Length": "0",
"Content-Type": "text/html; charset=utf-8",
"Date": "Wed,29 Nov 2023 06:19:30 GMT",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
},
"json": map[string]any{},
"results": map[string]any{},
"sslAge": int64(7004023369313149),
},
},
}

for _, tt := range tests {
for i := range tests {
tt := tests[i]

t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := gomplate.Serialize(tt.in)
if (err != nil) != tt.wantErr {
t.Errorf("serialize() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit 0141359

Please sign in to comment.