-
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 UUID V7 generator
- Loading branch information
Showing
8 changed files
with
265 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uuidv7 | ||
|
||
import ( | ||
uuidv7test "github.com/ankorstore/yokai/generate/generatetest/uuidv7" | ||
"github.com/ankorstore/yokai/generate/uuidv7" | ||
"go.uber.org/fx" | ||
) | ||
|
||
// FxTestUuidV7GeneratorFactoryParam is used to retrieve the provided generate-test-uuid-V7-value from Fx. | ||
type FxTestUuidV7GeneratorFactoryParam struct { | ||
fx.In | ||
Value string `name:"generate-test-uuid-v7-value"` | ||
} | ||
|
||
// TestUuidGeneratorV7Factory is a [uuidv7.Ui] implementation. | ||
type TestUuidGeneratorV7Factory struct { | ||
value string | ||
} | ||
|
||
// NewFxTestUuidV7GeneratorFactory returns a new [TestUuidGeneratorV7Factory], implementing [uuidv7.UuidV7GeneratorFactory]. | ||
func NewFxTestUuidV7GeneratorFactory(p FxTestUuidV7GeneratorFactoryParam) uuidv7.UuidV7GeneratorFactory { | ||
return &TestUuidGeneratorV7Factory{ | ||
value: p.Value, | ||
} | ||
} | ||
|
||
// Create returns a new [uuidv7.UuidV7Generator]. | ||
func (f *TestUuidGeneratorV7Factory) Create() uuidv7.UuidV7Generator { | ||
generator, err := uuidv7test.NewTestUuidV7Generator(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,40 @@ | ||
package uuidv7_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ankorstore/yokai/fxgenerate" | ||
fxgeneratetestuuidv7 "github.com/ankorstore/yokai/fxgenerate/fxgeneratetest/uuidv7" | ||
testuuidv7 "github.com/ankorstore/yokai/fxgenerate/testdata/uuidv7" | ||
"github.com/ankorstore/yokai/generate/uuidv7" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/fx" | ||
"go.uber.org/fx/fxtest" | ||
) | ||
|
||
func TestTestUuidV7Generator(t *testing.T) { | ||
t.Parallel() | ||
|
||
var generator uuidv7.UuidV7Generator | ||
|
||
fxtest.New( | ||
t, | ||
fx.NopLogger, | ||
fxgenerate.FxGenerateModule, | ||
fx.Provide( | ||
fx.Annotate( | ||
func() string { | ||
return testuuidv7.TestUUIDV7 | ||
}, | ||
fx.ResultTags(`name:"generate-test-uuid-v7-value"`), | ||
), | ||
), | ||
fx.Decorate(fxgeneratetestuuidv7.NewFxTestUuidV7GeneratorFactory), | ||
fx.Populate(&generator), | ||
).RequireStart().RequireStop() | ||
|
||
value, err := generator.Generate() | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, testuuidv7.TestUUIDV7, value.String()) | ||
} |
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
Oops, something went wrong.