MCPcopy Index your code
hub / github.com/DoNewsCode/core / TestModule_ProvideCommand

Function TestModule_ProvideCommand

otgorm/module_test.go:53–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestModule_ProvideCommand(t *testing.T) {
54 c := core.New(core.WithInline("gorm.default.database", "sqlite"),
55 core.WithInline("gorm.default.dsn", "file::memory:?cache=shared"))
56 c.ProvideEssentials()
57 c.Provide(di.Deps{
58 provideDBFactory(&providersOption{}),
59 di.Bind(new(Factory), new(Maker)),
60 })
61 c.AddModuleFunc(New)
62 mock := &Mock{}
63 c.AddModule(mock)
64 rootCmd := cobra.Command{}
65 c.ApplyRootCommand(&rootCmd)
66 assert.True(t, rootCmd.HasSubCommands())
67
68 cases := []struct {
69 name string
70 args []string
71 expect string
72 }{
73 {
74 "migrate",
75 []string{"database", "migrate"},
76 "migration",
77 },
78 {
79 "rollback",
80 []string{"database", "migrate", "--rollback"},
81 "rollback",
82 },
83 {
84 "seed",
85 []string{"database", "seed"},
86 "seeding",
87 },
88 }
89
90 for _, cc := range cases {
91 t.Run(cc.name, func(t *testing.T) {
92 rootCmd.SetArgs(cc.args)
93 rootCmd.Execute()
94 assert.Equal(t, cc.expect, mock.action)
95 })
96 }
97}
98
99func TestModule_ProvideRunGroup(t *testing.T) {
100 t.Parallel()

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
WithInlineFunction · 0.92
BindFunction · 0.92
provideDBFactoryFunction · 0.85
ProvideEssentialsMethod · 0.80
ProvideMethod · 0.80
AddModuleFuncMethod · 0.80
ApplyRootCommandMethod · 0.80
AddModuleMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected