| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package pprofile |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func TestProfileID(t *testing.T) { |
| 13 |
pid := ProfileID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) |
| 14 |
assert.Equal(t, [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}, [16]byte(pid)) |
| 15 |
assert.False(t, pid.IsEmpty()) |
| 16 |
} |
| 17 |
|
| 18 |
func TestNewProfileIDEmpty(t *testing.T) { |
| 19 |
pid := NewProfileIDEmpty() |
| 20 |
assert.Equal(t, [16]byte{}, [16]byte(pid)) |
| 21 |
assert.True(t, pid.IsEmpty()) |
| 22 |
} |
| 23 |
|
| 24 |
func TestProfileIDString(t *testing.T) { |
| 25 |
pid := ProfileID([16]byte{}) |
| 26 |
assert.Empty(t, pid.String()) |
| 27 |
|
| 28 |
pid = [16]byte{0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78} |
| 29 |
assert.Equal(t, "12345678123456781234567812345678", pid.String()) |
| 30 |
} |
| 31 |
|
| 32 |
func TestProfileIDImmutable(t *testing.T) { |
| 33 |
initialBytes := [16]byte{0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78} |
| 34 |
pid := ProfileID(initialBytes) |
| 35 |
assert.Equal(t, ProfileID(initialBytes), pid) |
| 36 |
|
| 37 |
// Get the bytes and try to mutate. |
| 38 |
pid[4] = 0x23 |
| 39 |
|
| 40 |
// Does not change the already created ProfileID. |
| 41 |
assert.NotEqual(t, ProfileID(initialBytes), pid) |
| 42 |
} |