Skip to content

Commit

Permalink
adds missing unittest for lelfpadding
Browse files Browse the repository at this point in the history
  • Loading branch information
staheri14 committed Jul 20, 2023
1 parent 17c0f58 commit eb7a49b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/namespace/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package namespace

import (
"bytes"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -195,3 +196,33 @@ func TestBytes(t *testing.T) {

assert.Equal(t, want, got)
}

func TestLeftPad(t *testing.T) {
tests := []struct {
input []byte
size int
expected []byte
}{
// input smaller than pad size
{[]byte{1, 2, 3}, 10, []byte{0, 0, 0, 0, 0, 0, 0, 1, 2, 3}},
{[]byte{1}, 5, []byte{0, 0, 0, 0, 1}},
{[]byte{1, 2}, 4, []byte{0, 0, 1, 2}},

// input equal to pad size
{[]byte{1, 2, 3}, 3, []byte{1, 2, 3}},
{[]byte{1, 2, 3, 4}, 4, []byte{1, 2, 3, 4}},

// input larger than pad size
{[]byte{1, 2, 3, 4, 5}, 4, []byte{1, 2, 3, 4, 5}},
{[]byte{1, 2, 3, 4, 5, 6, 7}, 3, []byte{1, 2, 3, 4, 5, 6, 7}},

// input size 0
{[]byte{}, 8, []byte{0, 0, 0, 0, 0, 0, 0, 0}},
{[]byte{}, 0, []byte{}},
}

for _, test := range tests {
result := leftPad(test.input, test.size)
assert.True(t, reflect.DeepEqual(result, test.expected))
}
}

0 comments on commit eb7a49b

Please sign in to comment.