Skip to content

Commit

Permalink
refactor: standardize UID method naming across registries
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed Nov 5, 2024
1 parent 588028d commit e27e16c
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 65 deletions.
16 changes: 8 additions & 8 deletions docs/advanced/how-to-create-a-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## File Naming Conventions

* `{{registry_name}}.go`: This file defines the registry, including key components like structs, interfaces, constants, and variables.
* `functions.go`: Contains the implementation of exported functions, making them accessible to other developers.
* `functions_test.go`: Includes tests for the exported functions to ensure they function as expected.
* `helpers.go`: Contains internal helper functions that support the registry but are not exposed for public use.
* `helpers_test.go`: Holds tests for the helper functions to validate their reliability.
- `{{registry_name}}.go`: This file defines the registry, including key components like structs, interfaces, constants, and variables.
- `functions.go`: Contains the implementation of exported functions, making them accessible to other developers.
- `functions_test.go`: Includes tests for the exported functions to ensure they function as expected.
- `helpers.go`: Contains internal helper functions that support the registry but are not exposed for public use.
- `helpers_test.go`: Holds tests for the helper functions to validate their reliability.

{% hint style="info" %}
This structure ensures consistency and maintainability across different registries, making it easier for developers to contribute and collaborate effectively.\
Expand Down Expand Up @@ -42,9 +42,9 @@ func NewRegistry() *OwnRegistry {
return &OwnRegistry{}
}

// Uid provides a unique identifier for your registry.
func (or *OwnRegistry) Uid() string {
return "organization/repo.ownregistry" // Ensure this identifier is unique and uses lowercase, prefixed by your handler/repo separated with a dot.
// UID provides a unique identifier for your registry.
func (or *OwnRegistry) UID() string {
return "organization/repo.ownregistry" // Ensure this identifier is unique and uses lowercase, prefixed by your handler/repo separated with a dot.
}

// LinkHandler connects the Handler to your registry, enabling runtime functionalities.
Expand Down
20 changes: 10 additions & 10 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type MockRegistry struct {

var errMock = errors.New("mock error")

func (m *MockRegistry) Uid() string {
func (m *MockRegistry) UID() string {
args := m.Called()
return args.String(0)
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestDefaultHandler_Logger(t *testing.T) {
func TestDefaultHandler_AddRegistries_Error(t *testing.T) {
mockRegistry := new(MockRegistry)
mockRegistry.linkHandlerMustCrash = true
mockRegistry.On("Uid").Return("mockRegistry")
mockRegistry.On("UID").Return("mockRegistry")
mockRegistry.On("LinkHandler", mock.Anything).Return(errMock)

dh := &DefaultHandler{
Expand All @@ -98,7 +98,7 @@ func TestDefaultHandler_AddRegistries_Error(t *testing.T) {
func TestDefaultHandler_AddRegistry_Error_RegisterFuiesctions(t *testing.T) {
mockRegistry := new(MockRegistry)
mockRegistry.registerFuncsMustCrash = true
mockRegistry.On("Uid").Return("mockRegistry")
mockRegistry.On("UID").Return("mockRegistry")
mockRegistry.On("LinkHandler", mock.Anything).Return()
mockRegistry.On("RegisterFunctions", mock.Anything).Return(errMock)

Expand All @@ -117,7 +117,7 @@ func TestDefaultHandler_AddRegistry_Error_RegisterFuiesctions(t *testing.T) {
func TestDefaultHandler_AddRegistry_Error_RegisteriesAliases(t *testing.T) {
mockRegistry := new(MockRegistryWithAlias)
mockRegistry.registerAliasesMustCrash = true
mockRegistry.On("Uid").Return("mockRegistry")
mockRegistry.On("UID").Return("mockRegistry")
mockRegistry.On("LinkHandler", mock.Anything).Return()
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
mockRegistry.On("RegisterAliases", mock.Anything).Return(errMock)
Expand All @@ -139,7 +139,7 @@ func TestDefaultHandler_AddRegistry_Error_RegisteriesAliases(t *testing.T) {
func TestDefaultHandler_AddRegistry_Error_RegisteriesNotices(t *testing.T) {
mockRegistry := new(MockRegistryWithNotices)
mockRegistry.registerNoticesMustCrash = true
mockRegistry.On("Uid").Return("mockRegistryWithNotices")
mockRegistry.On("UID").Return("mockRegistryWithNotices")
mockRegistry.On("LinkHandler", mock.Anything).Return()
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
mockRegistry.On("RegisterNotices", mock.Anything).Return()
Expand All @@ -163,7 +163,7 @@ func TestDefaultHandler_AddRegistry_Error_RegisteriesNotices(t *testing.T) {
// TestDefaultHandler_AddRegistry tests the AddRegistry method of DefaultHandler.
func TestDefaultHandler_AddRegistry(t *testing.T) {
mockRegistry := new(MockRegistry)
mockRegistry.On("Uid").Return("mockRegistry")
mockRegistry.On("UID").Return("mockRegistry")
mockRegistry.On("LinkHandler", mock.Anything).Return()
mockRegistry.On("RegisterFunctions", mock.Anything).Return()

Expand All @@ -184,12 +184,12 @@ func TestDefaultHandler_AddRegistry(t *testing.T) {
// TestDefaultHandler_AddRegistries tests the AddRegistries method of DefaultHandler.
func TestDefaultHandler_AddRegistries(t *testing.T) {
mockRegistry1 := new(MockRegistry)
mockRegistry1.On("Uid").Return("mockRegistry1")
mockRegistry1.On("UID").Return("mockRegistry1")
mockRegistry1.On("LinkHandler", mock.Anything).Return()
mockRegistry1.On("RegisterFunctions", mock.Anything).Return()

mockRegistry2 := new(MockRegistry)
mockRegistry2.On("Uid").Return("mockRegistry2")
mockRegistry2.On("UID").Return("mockRegistry2")
mockRegistry2.On("LinkHandler", mock.Anything).Return()
mockRegistry2.On("RegisterFunctions", mock.Anything).Return()

Expand All @@ -213,7 +213,7 @@ func TestDefaultHandler_AddRegistries(t *testing.T) {
// TestDefaultHandler_AddRegistryWithAlias tests AddRegistry when the registry also implements RegistryWithAlias.
func TestDefaultHandler_AddRegistryWithAlias(t *testing.T) {
mockRegistry := new(MockRegistryWithAlias)
mockRegistry.On("Uid").Return("mockRegistryWithAlias")
mockRegistry.On("UID").Return("mockRegistryWithAlias")
mockRegistry.On("LinkHandler", mock.Anything).Return()
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
mockRegistry.On("RegisterAliases", mock.Anything).Return()
Expand All @@ -236,7 +236,7 @@ func TestDefaultHandler_AddRegistryWithAlias(t *testing.T) {

func TestDefaultHandler_AddRegistryWithNotices(t *testing.T) {
mockRegistry := new(MockRegistryWithNotices)
mockRegistry.On("Uid").Return("mockRegistryWithNotices")
mockRegistry.On("UID").Return("mockRegistryWithNotices")
mockRegistry.On("LinkHandler", mock.Anything).Return()
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
mockRegistry.On("RegisterNotices", mock.Anything).Return()
Expand Down
4 changes: 2 additions & 2 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type FunctionMap = template.FuncMap
// performance of the template engine.
// It also allows for easy extension of the template functions by adding a new one.
type Registry interface {
// Uid returns the unique name of the registry. This name is used to identify
// UID returns the unique name of the registry. This name is used to identify
// the registry author and name and prevent duplicate registry registration.
Uid() string
UID() string
// LinkHandler links the given Handler to the registry.
// * This method help you to have access to the main handler and its
// * functionalities, like the logger, error handling, and more.
Expand Down
4 changes: 2 additions & 2 deletions registry/_example/_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func NewRegistry() *ExampleRegistry {
return &ExampleRegistry{}
}

// Uid returns the unique identifier of the registry.
func (or *ExampleRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (or *ExampleRegistry) UID() string {
return "go-sprout/sprout.exampleofregistry" // ! Must be unique and in lowercase, replace `exampleofregistry` with your registry name and `go-sprout/sprout` with your handle name
}

Expand Down
4 changes: 2 additions & 2 deletions registry/backward/backward.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func NewRegistry() *BackwardCompatibilityRegistry {
return &BackwardCompatibilityRegistry{}
}

// Uid returns the unique identifier of the registry.
func (bcr *BackwardCompatibilityRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (bcr *BackwardCompatibilityRegistry) UID() string {
return "go-sprout/sprout.backwardcompatibilitywithsprig"

Check warning on line 39 in registry/backward/backward.go

View check run for this annotation

Codecov / codecov/patch

registry/backward/backward.go#L38-L39

Added lines #L38 - L39 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/checksum/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *ChecksumRegistry {
return &ChecksumRegistry{}
}

// Uid returns the unique identifier of the registry.
func (cr *ChecksumRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (cr *ChecksumRegistry) UID() string {
return "go-sprout/sprout.checksum"

Check warning on line 16 in registry/checksum/checksum.go

View check run for this annotation

Codecov / codecov/patch

registry/checksum/checksum.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *ConversionRegistry {
return &ConversionRegistry{}
}

// Uid returns the unique identifier of the registry.
func (or *ConversionRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (or *ConversionRegistry) UID() string {
return "go-sprout/sprout.conversion"

Check warning on line 16 in registry/conversion/conversion.go

View check run for this annotation

Codecov / codecov/patch

registry/conversion/conversion.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func NewRegistry() *CryptoRegistry {
return &CryptoRegistry{}
}

// Uid returns the unique identifier of the crypto handler.
func (ch *CryptoRegistry) Uid() string {
// UID returns the unique identifier of the crypto handler.
func (ch *CryptoRegistry) UID() string {
return "go-sprout/sprout.crypto"
}

Expand Down
4 changes: 2 additions & 2 deletions registry/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *EncodingRegistry {
return &EncodingRegistry{}
}

// Uid returns the unique identifier of the registry.
func (or *EncodingRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (or *EncodingRegistry) UID() string {
return "go-sprout/sprout.encoding"

Check warning on line 16 in registry/encoding/encoding.go

View check run for this annotation

Codecov / codecov/patch

registry/encoding/encoding.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *EnvironmentRegistry {
return &EnvironmentRegistry{}
}

// Uid returns the unique identifier of the registry.
func (or *EnvironmentRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (or *EnvironmentRegistry) UID() string {
return "go-sprout/sprout.env"

Check warning on line 16 in registry/env/env.go

View check run for this annotation

Codecov / codecov/patch

registry/env/env.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *FileSystemRegistry {
return &FileSystemRegistry{}
}

// Uid returns the unique identifier of the registry.
func (fsr *FileSystemRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (fsr *FileSystemRegistry) UID() string {
return "go-sprout/sprout.filesystem"

Check warning on line 16 in registry/filesystem/filesystem.go

View check run for this annotation

Codecov / codecov/patch

registry/filesystem/filesystem.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/maps/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *MapsRegistry {
return &MapsRegistry{}
}

// Uid returns the unique identifier of the registry.
func (mr *MapsRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (mr *MapsRegistry) UID() string {
return "go-sprout/sprout.maps"
}

Check warning on line 18 in registry/maps/maps.go

View check run for this annotation

Codecov / codecov/patch

registry/maps/maps.go#L15-L18

Added lines #L15 - L18 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions registry/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func NewRegistry() *NetworkRegistry {
return &NetworkRegistry{}
}

// Uid returns the unique identifier of the registry.
func (nr *NetworkRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (nr *NetworkRegistry) UID() string {
return "go-sprout/sprout.network"
}

Expand Down
4 changes: 2 additions & 2 deletions registry/numeric/numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func NewRegistry() *NumericRegistry {
return &NumericRegistry{}
}

// Uid returns the unique identifier of the registry.
func (nr *NumericRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (nr *NumericRegistry) UID() string {
return "go-sprout/sprout.numeric"

Check warning on line 30 in registry/numeric/numeric.go

View check run for this annotation

Codecov / codecov/patch

registry/numeric/numeric.go#L29-L30

Added lines #L29 - L30 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func NewRegistry() *RandomRegistry {
return &RandomRegistry{}
}

// Uid returns the unique identifier of the registry.
func (rr *RandomRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (rr *RandomRegistry) UID() string {
return "go-sprout/sprout.random"

Check warning on line 47 in registry/random/random.go

View check run for this annotation

Codecov / codecov/patch

registry/random/random.go#L46-L47

Added lines #L46 - L47 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *ReflectRegistry {
return &ReflectRegistry{}
}

// Uid returns the unique identifier of the registry.
func (rr *ReflectRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (rr *ReflectRegistry) UID() string {
return "go-sprout/sprout.reflect"

Check warning on line 16 in registry/reflect/reflect.go

View check run for this annotation

Codecov / codecov/patch

registry/reflect/reflect.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/regexp/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *RegexpRegistry {
return &RegexpRegistry{}
}

// Uid returns the unique identifier of the registry.
func (rr *RegexpRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (rr *RegexpRegistry) UID() string {
return "go-sprout/sprout.regexp"

Check warning on line 16 in registry/regexp/regexp.go

View check run for this annotation

Codecov / codecov/patch

registry/regexp/regexp.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *SemverRegistry {
return &SemverRegistry{}
}

// Uid returns the unique identifier of the registry.
func (sr *SemverRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (sr *SemverRegistry) UID() string {
return "go-sprout/sprout.semver"

Check warning on line 16 in registry/semver/semver.go

View check run for this annotation

Codecov / codecov/patch

registry/semver/semver.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *SlicesRegistry {
return &SlicesRegistry{}
}

// Uid returns the unique identifier of the registry.
func (sr *SlicesRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (sr *SlicesRegistry) UID() string {
return "go-sprout/sprout.slices"

Check warning on line 16 in registry/slices/slices.go

View check run for this annotation

Codecov / codecov/patch

registry/slices/slices.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/std/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *StdRegistry {
return &StdRegistry{}
}

// Uid returns the unique identifier of the registry.
func (sr *StdRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (sr *StdRegistry) UID() string {
return "go-sprout/sprout.std"

Check warning on line 16 in registry/std/std.go

View check run for this annotation

Codecov / codecov/patch

registry/std/std.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/strings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func NewRegistry() *StringsRegistry {
return &StringsRegistry{}
}

// Uid returns the unique identifier of the registry.
func (sr *StringsRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (sr *StringsRegistry) UID() string {
return "go-sprout/sprout.strings"

Check warning on line 86 in registry/strings/strings.go

View check run for this annotation

Codecov / codecov/patch

registry/strings/strings.go#L85-L86

Added lines #L85 - L86 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *TimeRegistry {
return &TimeRegistry{}
}

// Uid returns the unique identifier of the registry.
func (tr *TimeRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (tr *TimeRegistry) UID() string {
return "go-sprout/sprout.time"

Check warning on line 16 in registry/time/time.go

View check run for this annotation

Codecov / codecov/patch

registry/time/time.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry/uniqueid/uniqueid.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func NewRegistry() *UniqueIDRegistry {
return &UniqueIDRegistry{}
}

// Uid returns the unique identifier of the registry.
func (ur *UniqueIDRegistry) Uid() string {
// UID returns the unique identifier of the registry.
func (ur *UniqueIDRegistry) UID() string {
return "go-sprout/sprout.uniqueid"

Check warning on line 16 in registry/uniqueid/uniqueid.go

View check run for this annotation

Codecov / codecov/patch

registry/uniqueid/uniqueid.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

Expand Down
4 changes: 2 additions & 2 deletions registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func TestAddAlias(t *testing.T) {
func TestWithRegistries(t *testing.T) {
// Define two registries with functions and aliases
mockRegistry1 := new(MockRegistry)
mockRegistry1.On("Uid").Return("mockRegistry1")
mockRegistry1.On("UID").Return("mockRegistry1")
mockRegistry1.On("LinkHandler", mock.Anything).Return(nil)
mockRegistry1.On("RegisterFunctions", mock.Anything).Return(nil)

mockRegistry2 := new(MockRegistry)
mockRegistry2.linkHandlerMustCrash = true
mockRegistry2.On("Uid").Return("mockRegistry2")
mockRegistry2.On("UID").Return("mockRegistry2")
mockRegistry2.On("LinkHandler", mock.Anything).Return(nil)
mockRegistry1.On("RegisterFunctions", mock.Anything).Return(nil)

Expand Down
6 changes: 3 additions & 3 deletions sprigin/sprig_backward_compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func TestSprigHandler(t *testing.T) {

assert.Len(t, handler.registries, 18) // Hardcoded for backward compatibility

registriesUids := []string{}
registriesUIDs := []string{}
for _, registry := range handler.registries {
registriesUids = append(registriesUids, registry.Uid())
registriesUIDs = append(registriesUIDs, registry.UID())
}

assert.ElementsMatch(t, registriesUids, []string{
assert.ElementsMatch(t, registriesUIDs, []string{
"go-sprout/sprout.std",
"go-sprout/sprout.uniqueid",
"go-sprout/sprout.semver",
Expand Down

0 comments on commit e27e16c

Please sign in to comment.