| 
									
										
										
										
											2025-03-15 15:36:43 -05:00
										 |  |  | package nomino | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/google/uuid" | 
					
						
							|  |  |  | 	"github.com/stretchr/testify/assert" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestUUID(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2025-03-16 12:38:36 -05:00
										 |  |  | 	st, err := UUID(nil)(nil) | 
					
						
							| 
									
										
										
										
											2025-03-15 15:36:43 -05:00
										 |  |  | 	assert.NoError(t, err) | 
					
						
							|  |  |  | 	_, parseErr := uuid.Parse(st) | 
					
						
							|  |  |  | 	assert.NoError(t, parseErr) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type badRead struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (badRead) Read([]byte) (int, error) { | 
					
						
							| 
									
										
										
										
											2025-03-19 18:05:16 -05:00
										 |  |  | 	return 0, errTest | 
					
						
							| 
									
										
										
										
											2025-03-15 15:36:43 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestUUIDFail(t *testing.T) { | 
					
						
							|  |  |  | 	uuid.SetRand(badRead{}) | 
					
						
							|  |  |  | 	defer uuid.SetRand(nil) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-16 12:38:36 -05:00
										 |  |  | 	_, err := UUID(nil)(nil) | 
					
						
							| 
									
										
										
										
											2025-03-19 18:05:16 -05:00
										 |  |  | 	assert.ErrorIs(t, err, errTest) | 
					
						
							| 
									
										
										
										
											2025-03-15 15:36:43 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestRand(t *testing.T) { | 
					
						
							|  |  |  | 	st, err := Random()(nil) | 
					
						
							|  |  |  | 	assert.NoError(t, err) | 
					
						
							|  |  |  | 	assert.Len(t, st, 8) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestRandLen(t *testing.T) { | 
					
						
							|  |  |  | 	st, err := Random(RandomLength(32))(nil) | 
					
						
							|  |  |  | 	assert.NoError(t, err) | 
					
						
							|  |  |  | 	assert.Len(t, st, 32) | 
					
						
							|  |  |  | } |