-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fxgenerate): Added UUIDv6 generation (#303)
- Loading branch information
Showing
9 changed files
with
271 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uuidv6 | ||
|
||
import ( | ||
uuidv6test "github.com/ankorstore/yokai/generate/generatetest/uuidv6" | ||
"github.com/ankorstore/yokai/generate/uuidv6" | ||
"go.uber.org/fx" | ||
) | ||
|
||
// FxTestUuidV6GeneratorFactoryParam is used to retrieve the provided generate-test-uuid-V6-value from Fx. | ||
type FxTestUuidV6GeneratorFactoryParam struct { | ||
fx.In | ||
Value string `name:"generate-test-uuid-v6-value"` | ||
} | ||
|
||
// TestUuidGeneratorV6Factory is a [uuidv6.Ui] implementation. | ||
type TestUuidGeneratorV6Factory struct { | ||
value string | ||
} | ||
|
||
// NewFxTestUuidV6GeneratorFactory returns a new [TestUuidGeneratorV6Factory], implementing [uuidv6.UuidV6GeneratorFactory]. | ||
func NewFxTestUuidV6GeneratorFactory(p FxTestUuidV6GeneratorFactoryParam) uuidv6.UuidV6GeneratorFactory { | ||
return &TestUuidGeneratorV6Factory{ | ||
value: p.Value, | ||
} | ||
} | ||
|
||
// Create returns a new [uuidv6.UuidV6Generator]. | ||
func (f *TestUuidGeneratorV6Factory) Create() uuidv6.UuidV6Generator { | ||
generator, err := uuidv6test.NewTestUuidV6Generator(f.value) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return generator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package uuidv6_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ankorstore/yokai/fxgenerate" | ||
fxgeneratetestuuidv6 "github.com/ankorstore/yokai/fxgenerate/fxgeneratetest/uuidv6" | ||
testuuidv6 "github.com/ankorstore/yokai/fxgenerate/testdata/uuidv6" | ||
"github.com/ankorstore/yokai/generate/uuidv6" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/fx" | ||
"go.uber.org/fx/fxtest" | ||
) | ||
|
||
func TestTestUuidV6GeneratorSuccess(t *testing.T) { | ||
t.Parallel() | ||
|
||
var generator uuidv6.UuidV6Generator | ||
|
||
fxtest.New( | ||
t, | ||
fx.NopLogger, | ||
fxgenerate.FxGenerateModule, | ||
fx.Provide( | ||
fx.Annotate( | ||
func() string { | ||
return testuuidv6.TestUUIDV6 | ||
}, | ||
fx.ResultTags(`name:"generate-test-uuid-v6-value"`), | ||
), | ||
), | ||
fx.Decorate(fxgeneratetestuuidv6.NewFxTestUuidV6GeneratorFactory), | ||
fx.Populate(&generator), | ||
).RequireStart().RequireStop() | ||
|
||
value, err := generator.Generate() | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, testuuidv6.TestUUIDV6, value.String()) | ||
} | ||
|
||
func TestTestUuidV6GeneratorError(t *testing.T) { | ||
t.Parallel() | ||
|
||
var generator uuidv6.UuidV6Generator | ||
|
||
fxtest.New( | ||
t, | ||
fx.NopLogger, | ||
fxgenerate.FxGenerateModule, | ||
fx.Provide( | ||
fx.Annotate( | ||
func() string { | ||
return "invalid" | ||
}, | ||
fx.ResultTags(`name:"generate-test-uuid-v6-value"`), | ||
), | ||
), | ||
fx.Decorate(fxgeneratetestuuidv6.NewFxTestUuidV6GeneratorFactory), | ||
fx.Populate(&generator), | ||
).RequireStart().RequireStop() | ||
|
||
assert.Nil(t, generator) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package uuidv6 | ||
|
||
import ( | ||
uuidtest "github.com/ankorstore/yokai/generate/generatetest/uuidv6" | ||
"github.com/ankorstore/yokai/generate/uuidv6" | ||
) | ||
|
||
const TestUUIDV6 = "1efa5a47-e5d2-6d70-8953-776e81422ff3" | ||
|
||
type TestStaticUuidV6GeneratorFactory struct{} | ||
|
||
func NewTestStaticUuidV6GeneratorFactory() uuidv6.UuidV6GeneratorFactory { | ||
return &TestStaticUuidV6GeneratorFactory{} | ||
} | ||
|
||
func (f *TestStaticUuidV6GeneratorFactory) Create() uuidv6.UuidV6Generator { | ||
//nolint:errcheck | ||
generator, _ := uuidtest.NewTestUuidV6Generator(TestUUIDV6) | ||
|
||
return generator | ||
} |