Anton Petruhin 3 лет назад
Родитель
Сommit
7bbf670a72
3 измененных файлов с 9 добавлено и 6 удалено
  1. 1 0
      Dockerfile
  2. 1 1
      ebpftracer/Makefile
  3. 7 5
      ebpftracer/tracer_test.go

+ 1 - 0
Dockerfile

@@ -5,6 +5,7 @@ COPY go.sum /tmp/src/
 WORKDIR /tmp/src/
 RUN go mod download
 COPY . /tmp/src/
+RUN CGO_ENABLED=1 go test ./...
 ARG VERSION=unknown
 RUN CGO_ENABLED=1 go install -mod=readonly -ldflags "-X main.version=$VERSION" /tmp/src
 

+ 1 - 1
ebpftracer/Makefile

@@ -8,7 +8,7 @@ test: test_vm1 test_vm2 test_vm3 test_vm4
 
 define test_in_vm
 	@echo ===TESTING IN $(1)===
-	vagrant ssh $(1) -c "uname -r && cd /tmp/src && sudo go test -p 1 -count 1 -v ./ebpftracer/..."
+	vagrant ssh $(1) -c "uname -r && cd /tmp/src && VM=$(1) sudo go test -p 1 -count 1 -v ./ebpftracer/..."
 	@echo
 endef
 

+ 7 - 5
ebpftracer/tracer_test.go

@@ -1,3 +1,5 @@
+//go:build amd64
+
 package ebpftracer
 
 import (
@@ -20,14 +22,14 @@ import (
 	"time"
 )
 
-func skipIfNotRoot(t *testing.T) {
-	if os.Getuid() != 0 {
+func skipIfNotVM(t *testing.T) {
+	if os.Getenv("VM") == "" {
 		t.SkipNow()
 	}
 }
 
 func TestProcessEvents(t *testing.T) {
-	skipIfNotRoot(t)
+	skipIfNotVM(t)
 	src := `
 		package main
 		
@@ -103,7 +105,7 @@ func TestProcessEvents(t *testing.T) {
 }
 
 func TestTcpEvents(t *testing.T) {
-	skipIfNotRoot(t)
+	skipIfNotVM(t)
 	l, err := net.Listen("tcp", "127.0.0.1:8080")
 	require.NoError(t, err)
 	listenAddr := l.Addr().String()
@@ -222,7 +224,7 @@ func TestTcpEvents(t *testing.T) {
 }
 
 func TestFileEvents(t *testing.T) {
-	skipIfNotRoot(t)
+	skipIfNotVM(t)
 	src := `
 		package main