Skip to content

Commit d013ad7

Browse files
committed
Fix realpath usage and jmx discovery test
1 parent 36ef083 commit d013ad7

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

.github/workflows/integration-test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ jobs:
238238
target="smartagent-integration-test-with-cover"
239239
fi
240240
export CONTAINER_COVER_DEST="/etc/otel/collector/coverage"
241-
export CONTAINER_COVER_SRC=$(realpath)/tests/coverage
241+
export CONTAINER_COVER_SRC=$(realpath .)/tests/coverage
242242
make $target 2>&1 | tee $TEST_OUTPUT
243243
exit_status=${PIPESTATUS[0]}
244244
echo "Exit status: $exit_status"
@@ -326,7 +326,7 @@ jobs:
326326
target="smartagent-integration-test-with-cover"
327327
fi
328328
export CONTAINER_COVER_DEST="/etc/otel/collector/coverage"
329-
export CONTAINER_COVER_SRC=$(realpath)/tests/coverage
329+
export CONTAINER_COVER_SRC=$(realpath .)/tests/coverage
330330
make $target 2>&1 | tee $TEST_OUTPUT
331331
exit_status=${PIPESTATUS[0]}
332332
echo "Exit status: $exit_status"
@@ -406,7 +406,7 @@ jobs:
406406
- name: Run ${{ matrix.SERVICE }} Discovery Integration Test With Cover
407407
run: |
408408
export CONTAINER_COVER_DEST="/etc/otel/collector/coverage"
409-
export CONTAINER_COVER_SRC=$(realpath)/tests/coverage
409+
export CONTAINER_COVER_SRC=$(realpath .)/tests/coverage
410410
make integration-test-${{ matrix.SERVICE }}-discovery-with-cover
411411
env:
412412
SPLUNK_OTEL_COLLECTOR_IMAGE: 'otelcol:latest'
@@ -478,7 +478,7 @@ jobs:
478478
- name: Run ${{ matrix.SERVICE }} Discovery Kubernetes Integration Test With Cover
479479
run: |
480480
export CONTAINER_COVER_DEST="/etc/otel/collector/coverage"
481-
export CONTAINER_COVER_SRC=$(realpath)/tests/coverage
481+
export CONTAINER_COVER_SRC=$(realpath .)/tests/coverage
482482
KUBECONFIG=$HOME/.kube/config SKIP_TEARDOWN=true make integration-test-${{ matrix.SERVICE }}-discovery-k8s-with-cover
483483
- name: Print logs
484484
if: failure()

tests/receivers/jmx/cassandra/jmx_cassandra_discovery_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"os"
2424
"path/filepath"
2525
"runtime"
26-
"strings"
2726
"syscall"
2827
"testing"
2928
"time"
@@ -89,25 +88,24 @@ func jmxCassandraAutoDiscoveryHelper(t *testing.T, ctx context.Context, configFi
8988
return nil, err
9089
}
9190

92-
var path string
93-
var mountPath string
94-
testDirName := "tests"
95-
if path, err = filepath.Abs("."); err == nil {
91+
coverDest := os.Getenv("CONTAINER_COVER_DEST")
92+
coverSrc := os.Getenv("CONTAINER_COVER_SRC")
93+
var coverDirBind string
94+
if coverSrc != "" && coverDest != "" {
95+
coverDirBind = fmt.Sprintf("%s:%s", coverSrc, coverDest)
96+
9697
// Coverage should all be under the top-level `tests/coverage` dir that's mounted
9798
// to the container. This string parsing logic is to ensure different sub-directory
9899
// tests all put their coverage in the top-level directory.
99-
index := strings.Index(path, testDirName)
100-
mountPath = filepath.Join(path[0:index+len(testDirName)], "coverage")
101-
fmt.Printf("PWD: %s, Container mount, source: %s, destination: %s\n", path, mountPath, "/etc/otel/collector/coverage")
102-
if fileStat, err := os.Stat(filepath.Join(path[0:index+len(testDirName)], "coverage")); err == nil {
100+
fmt.Printf("Container mount, source: %s, destination: %s\n", coverSrc, coverDest)
101+
if fileStat, err := os.Stat(coverSrc); err == nil {
103102
fmt.Printf("Coverage dir from source stat succeeded, is dir? %v, mode: %v\n", fileStat.IsDir(), fileStat.Mode())
104103
} else {
105104
fmt.Printf("coverdir stat err: %v\n", err)
106105
}
107106
} else {
108-
fmt.Printf("Container mount err: %v\n", err)
107+
fmt.Printf("coversrc or coverdest not set")
109108
}
110-
coverDirBind := fmt.Sprintf("%s:/etc/otel/collector/coverage", mountPath)
111109

112110
currPath, err := filepath.Abs(filepath.Join(".", "testdata"))
113111
if err != nil {
@@ -128,7 +126,7 @@ func jmxCassandraAutoDiscoveryHelper(t *testing.T, ctx context.Context, configFi
128126
"SPLUNK_OTEL_COLLECTOR_IMAGE": "otelcol:latest",
129127
"USERNAME": "hello",
130128
"PASSWORD": "world",
131-
"GOCOVERDIR": "/etc/otel/collector/coverage",
129+
"GOCOVERDIR": coverDest,
132130
},
133131
Entrypoint: []string{"/otelcol", "--config", "/home/otel-local-config.yaml"},
134132
Files: []testcontainers.ContainerFile{

0 commit comments

Comments
 (0)