github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/vm/proxyapp/proxyappclient_mocks_test.go (about) 1 // Copyright 2022 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package proxyapp 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/google/syzkaller/vm/proxyapp/mocks" 11 "github.com/google/syzkaller/vm/proxyapp/proxyrpc" 12 "github.com/stretchr/testify/mock" 13 ) 14 15 var ( 16 _ subProcessCmd = &mocks.SubProcessCmd{} 17 _ proxyrpc.ProxyAppInterface = &mocks.ProxyAppInterface{} 18 ) 19 20 type mockCommandRunner struct { 21 *mocks.SubProcessCmd 22 ctx context.Context 23 onWaitCalled chan bool 24 } 25 26 func makeMockCommandRunner(t *testing.T) (*mockCommandRunner, *proxyAppParams) { 27 cmdRunner := &mockCommandRunner{ 28 SubProcessCmd: mocks.NewSubProcessCmd(t), 29 onWaitCalled: make(chan bool, 1), 30 } 31 32 params := makeTestParams() 33 params.CommandRunner = func(ctx context.Context, cmd string, params ...string) subProcessCmd { 34 cmdRunner.ctx = ctx 35 return cmdRunner 36 } 37 return cmdRunner, params 38 } 39 40 func (cmd *mockCommandRunner) Wait() error { 41 cmd.onWaitCalled <- true 42 return cmd.SubProcessCmd.Wait() 43 } 44 45 type mockProxyAppInterface struct { 46 *mocks.ProxyAppInterface 47 OnLogsReceived chan bool 48 } 49 50 type tNewProxyAppInterface interface { 51 mock.TestingT 52 Cleanup(func()) 53 } 54 55 func makeMockProxyAppInterface(t tNewProxyAppInterface) *mockProxyAppInterface { 56 return &mockProxyAppInterface{ 57 ProxyAppInterface: mocks.NewProxyAppInterface(t), 58 OnLogsReceived: make(chan bool, 1), // 1 is enough as we read it just once 59 } 60 }