github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/crypto/rand_test.go (about)

     1  package crypto
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func BenchmarkRandomBytes(b *testing.B) {
    10  	for i := 0; i < b.N; i++ {
    11  		_, _ = RandomBytes(128)
    12  	}
    13  }
    14  
    15  func TestRandomBytesSize(t *testing.T) {
    16  	bytes, err := RandomBytes(128)
    17  	assert.NoError(t, err)
    18  
    19  	assert.Equal(t, 128, len(bytes))
    20  }
    21  
    22  func TestRandomBytesAreNotEqual(t *testing.T) {
    23  	bytes1, err := RandomBytes(128)
    24  	assert.NoError(t, err)
    25  
    26  	bytes2, err := RandomBytes(128)
    27  	assert.NoError(t, err)
    28  
    29  	assert.NotEqual(t, bytes1, bytes2)
    30  }
    31  
    32  func TestUrlSafeStringSize(t *testing.T) {
    33  	str, err := RandomUrlSafeString(128)
    34  	assert.NoError(t, err)
    35  
    36  	assert.Equal(t, 128, len(str))
    37  }