(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func 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 | |
| 99 | func TestModule_ProvideRunGroup(t *testing.T) { |
| 100 | t.Parallel() |
nothing calls this directly
no test coverage detected