Skip to content

Commit

Permalink
Build a test binary for benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroPower committed Dec 23, 2024
1 parent 99a5fc5 commit 5ddd6b3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ builds:
- -trimpath
tags:
- netgo
hooks: &hooks
pre:
- cmd: >-
{{- if and (eq .Arch .Runtime.Goarch) (eq .Os .Runtime.Goos) }}
go test -c -vet=all -tags=netgo -ldflags=-s
-o ./dist/{{ .ProjectName }}.test/ ./pkg/...
{{- else }}
echo "Skipping test binary build for non-native platform"
{{- end }}
- id: kclx-darwin
main: ./cmd/kclx
Expand All @@ -67,6 +76,7 @@ builds:
- -trimpath
tags:
- netgo
hooks: *hooks

dockers:
- goos: linux
Expand Down
5 changes: 4 additions & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ tasks:
go-build:
desc: Builds Go binaries
cmds:
- goreleaser build --snapshot --clean
- |-
export HOSTNAME="{{ .HOSTNAME }}"
export SDK_PATH="{{ .SDK_PATH }}"
goreleaser build --snapshot --clean --verbose
go-build-images:
desc: Builds Go binaries and Docker images
Expand Down
45 changes: 45 additions & 0 deletions pkg/helm/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,48 @@ patch = lambda resource: {str:} -> {str:} {
t.Fatalf("result is not correct, %s", string(obj0md))
}
}

func BenchmarkPluginHelmTemplate(b *testing.B) {

Check failure on line 170 in pkg/helm/plugin_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

code := `
import kcl_plugin.helm
_chart = helm.template(
chart="wakatime-exporter",
repo_url="https://jacobcolvin.com/helm-charts",
target_revision="0.1.0",
values={service.main.enabled = False},
)
{result = _chart}
`

client := native.NewNativeServiceClient()
_, err := client.ExecProgram(&gpyrpc.ExecProgram_Args{
KFilenameList: []string{"main.k"},
KCodeList: []string{code},
Args: []*gpyrpc.Argument{},
})
if err != nil {
b.Fatal(err)
}

b.ResetTimer()

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
client := native.NewNativeServiceClient()
result, err := client.ExecProgram(&gpyrpc.ExecProgram_Args{
KFilenameList: []string{"main.k"},
KCodeList: []string{code},
Args: []*gpyrpc.Argument{},
})
if err != nil {
b.Fatal(err)
}
if result.GetErrMessage() != "" {
b.Fatal(result.GetErrMessage())
}
}
})
}

0 comments on commit 5ddd6b3

Please sign in to comment.