Explorar el Código

Test: Remove temporary directory afterwards (#4045)

zonescape hace 1 año
padre
commit
ce8c415d43
Se han modificado 2 ficheros con 14 adiciones y 0 borrados
  1. 2 0
      testing/scenarios/common.go
  2. 12 0
      testing/scenarios/main_test.go

+ 2 - 0
testing/scenarios/common.go

@@ -96,6 +96,7 @@ func InitializeServerConfig(config *core.Config) (*exec.Cmd, error) {
 
 
 var (
 var (
 	testBinaryPath    string
 	testBinaryPath    string
+	testBinaryCleanFn func()
 	testBinaryPathGen sync.Once
 	testBinaryPathGen sync.Once
 )
 )
 
 
@@ -108,6 +109,7 @@ func genTestBinaryPath() {
 				return err
 				return err
 			}
 			}
 			tempDir = dir
 			tempDir = dir
+			testBinaryCleanFn = func() { os.RemoveAll(dir) }
 			return nil
 			return nil
 		}))
 		}))
 		file := filepath.Join(tempDir, "xray.test")
 		file := filepath.Join(tempDir, "xray.test")

+ 12 - 0
testing/scenarios/main_test.go

@@ -0,0 +1,12 @@
+package scenarios
+
+import (
+	"testing"
+)
+
+func TestMain(m *testing.M) {
+	genTestBinaryPath()
+	defer testBinaryCleanFn()
+
+	m.Run()
+}