Skip to content

Commit

Permalink
test: add message testing
Browse files Browse the repository at this point in the history
Signed-off-by: Djalal Harouni <tixxdz@gmail.com>
  • Loading branch information
tixxdz committed Jan 9, 2024
1 parent 8a2783d commit 93a0c65
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/sensors/tracing/message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon

package tracing

import (
"strings"
"testing"

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

func TestGetPolicyMessage(t *testing.T) {
msg, err := getPolicyMessage("")
require.Empty(t, msg)
require.Equal(t, err, ErrMsgSyntaxEmpty)

msg, err = getPolicyMessage("a")
require.Empty(t, msg)
require.Equal(t, err, ErrMsgSyntaxShort)

msg, err = getPolicyMessage("test")
require.NoError(t, err)
require.Equal(t, msg, "test")

msg, err = getPolicyMessage(strings.Repeat("a", TpMaxMessageLen+1))
require.Equal(t, err, ErrMsgSyntaxLong)
require.Equal(t, TpMaxMessageLen, len(msg))
}

0 comments on commit 93a0c65

Please sign in to comment.