Documentation
¶
Overview ¶
Package names provides human-readable name assignment for workers. Names are generated using a Docker-like approach: adjective + noun combinations. This provides a large variety of unique, memorable names.
Index ¶
- func GenerateName() string
- func GetAllAdjectives() []string
- func GetAllNouns() []string
- func GetCombinationCount() int
- func GetNextAvailableName(ctx context.Context, db DB) (string, error)
- func ParseName(name string) (adjective, noun string)
- func ReleaseName(_ context.Context, _ DB, _ string) error
- type DB
- type DefaultGenerator
- type Generator
- type GeneratorMock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateName ¶
func GenerateName() string
GenerateName creates a random name by combining an adjective and a noun. Format: "adjective_noun" (e.g., "brave_einstein", "clever_curie")
func GetAllAdjectives ¶
func GetAllAdjectives() []string
GetAllAdjectives returns the full list of adjectives.
func GetCombinationCount ¶
func GetCombinationCount() int
GetCombinationCount returns the total number of possible name combinations.
func GetNextAvailableName ¶
GetNextAvailableName returns a unique name that is not currently in use. It generates random adjective_noun combinations until it finds one that's available. Returns empty string if it fails to generate a unique name after many attempts (extremely unlikely given the large combination space).
Types ¶
type DB ¶
type DB interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
DB is the interface required for name operations.
type DefaultGenerator ¶
type DefaultGenerator struct{}
DefaultGenerator is the default implementation of the Generator interface.
func (*DefaultGenerator) GetNextAvailableName ¶
GetNextAvailableName implements Generator.
type GeneratorMock ¶
type GeneratorMock struct {
// GetNextAvailableNameFunc mocks the GetNextAvailableName method.
GetNextAvailableNameFunc func(ctx context.Context, db DB) (string, error)
// contains filtered or unexported fields
}
GeneratorMock is a mock implementation of Generator.
func TestSomethingThatUsesGenerator(t *testing.T) {
// make and configure a mocked Generator
mockedGenerator := &GeneratorMock{
GetNextAvailableNameFunc: func(ctx context.Context, db DB) (string, error) {
panic("mock out the GetNextAvailableName method")
},
}
// use mockedGenerator in code that requires Generator
// and then make assertions.
}
func (*GeneratorMock) GetNextAvailableName ¶
GetNextAvailableName calls GetNextAvailableNameFunc.
func (*GeneratorMock) GetNextAvailableNameCalls ¶
func (mock *GeneratorMock) GetNextAvailableNameCalls() []struct { Ctx context.Context Db DB }
GetNextAvailableNameCalls gets all the calls that were made to GetNextAvailableName. Check the length with:
len(mockedGenerator.GetNextAvailableNameCalls())