11package test
22
33import (
4+ "context"
45 "fmt"
56 "net/http"
67 "os"
78 "os/exec"
8- "path"
99 "testing"
1010
1111 "github.com/containerd/continuity/fs/fstest"
@@ -24,12 +24,6 @@ func tmpdir(tb testing.TB, appliers ...fstest.Applier) string {
2424
2525type cmdOpt func (* exec.Cmd )
2626
27- func withEnv (env ... string ) cmdOpt {
28- return func (cmd * exec.Cmd ) {
29- cmd .Env = append (cmd .Env , env ... )
30- }
31- }
32-
3327func withArgs (args ... string ) cmdOpt {
3428 return func (cmd * exec.Cmd ) {
3529 cmd .Args = append (cmd .Args , args ... )
@@ -43,7 +37,7 @@ func withDir(dir string) cmdOpt {
4337}
4438
4539func buildxCmd (sb testutil.Sandbox , opts ... cmdOpt ) * exec.Cmd {
46- cmd := exec .Command ( sb .BuildxBin ())
40+ cmd := exec .CommandContext ( context . Background (), sb .BuildxBin ()) //nolint:gosec // test utility
4741 cmd .Env = append ([]string {}, os .Environ ()... )
4842 for _ , opt := range opts {
4943 opt (cmd )
@@ -64,26 +58,6 @@ func buildxBuildCmd(sb testutil.Sandbox, opts ...cmdOpt) (string, error) {
6458 return string (out ), err
6559}
6660
67- func buildctlCmd (sb testutil.Sandbox , opts ... cmdOpt ) * exec.Cmd {
68- cmd := exec .Command (path .Join (sb .BuildKitBinsDir (), sb .Name (), "buildctl" ))
69- cmd .Args = append (cmd .Args , "--debug" )
70- if buildkitAddr := sb .Address (); buildkitAddr != "" {
71- cmd .Args = append (cmd .Args , "--addr" , buildkitAddr )
72- }
73- cmd .Env = append ([]string {}, os .Environ ()... )
74- for _ , opt := range opts {
75- opt (cmd )
76- }
77- return cmd
78- }
79-
80- func buildctlBuildCmd (sb testutil.Sandbox , opts ... cmdOpt ) (string , error ) {
81- opts = append ([]cmdOpt {withArgs ("build" , "--frontend=dockerfile.v0" )}, opts ... )
82- cmd := buildctlCmd (sb , opts ... )
83- out , err := cmd .CombinedOutput ()
84- return string (out ), err
85- }
86-
8761func reportBuildkitdAlloc (b * testing.B , sb testutil.Sandbox , cb func ()) {
8862 beforeAlloc , errb := buildkitdAlloc (sb )
8963 cb ()
@@ -95,7 +69,11 @@ func reportBuildkitdAlloc(b *testing.B, sb testutil.Sandbox, cb func()) {
9569
9670func buildkitdAlloc (sb testutil.Sandbox ) (int64 , error ) {
9771 client := & http.Client {}
98- resp , err := client .Get (fmt .Sprintf ("http://%s/debug/pprof/heap?gc=1" , sb .DebugAddress ()))
72+ req , err := http .NewRequestWithContext (context .Background (), http .MethodGet , fmt .Sprintf ("http://%s/debug/pprof/heap?gc=1" , sb .DebugAddress ()), nil )
73+ if err != nil {
74+ return 0 , err
75+ }
76+ resp , err := client .Do (req )
9977 if err != nil {
10078 return 0 , err
10179 }
0 commit comments