github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/rpcplugin/rpcplugintest/rpcplugintest.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package rpcplugintest 5 6 import ( 7 "io/ioutil" 8 "os" 9 "os/exec" 10 "path/filepath" 11 "testing" 12 13 "github.com/stretchr/testify/require" 14 ) 15 16 func CompileGo(t *testing.T, sourceCode, outputPath string) { 17 dir, err := ioutil.TempDir(".", "") 18 require.NoError(t, err) 19 defer os.RemoveAll(dir) 20 require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "main.go"), []byte(sourceCode), 0600)) 21 cmd := exec.Command("go", "build", "-o", outputPath, "main.go") 22 cmd.Dir = dir 23 cmd.Stdout = os.Stdout 24 cmd.Stderr = os.Stderr 25 require.NoError(t, cmd.Run()) 26 }