about summary refs log tree commit diff
path: root/main/civisibility/utils/names_test.go
blob: 019aa0200a228edf54fdc584c7bb7c47471dd43e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024 Datadog, Inc.

package utils

import (
	"runtime"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestGetModuleAndSuiteName(t *testing.T) {
	pc, _, _, _ := runtime.Caller(0) // Get the program counter of this function
	_, suite := GetModuleAndSuiteName(pc)
	// expectedModule := "gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/utils"
	expectedSuite := "names_test.go"

	// assert.True(t, strings.HasPrefix(module, expectedModule))
	assert.Equal(t, expectedSuite, suite)
}

func TestGetStacktrace(t *testing.T) {
	stacktrace := GetStacktrace(0)
	assert.Contains(t, stacktrace, "names_test.go")     // Ensure that the current test file is part of the stack trace
	assert.Contains(t, stacktrace, "TestGetStacktrace") // Ensure that the current test function is part of the stack trace
}

func TestGetStacktraceWithSkip(t *testing.T) {
	stacktrace := getStacktraceHelper()
	assert.Contains(t, stacktrace, "names_test.go")
	assert.NotContains(t, stacktrace, "getStacktraceHelper") // Ensure the helper function is skipped
}

func getStacktraceHelper() string {
	return GetStacktrace(1) // Skip this helper function frame
}