(t *testing.T)
| 97 | } |
| 98 | |
| 99 | func TestModule_ProvideRunGroup(t *testing.T) { |
| 100 | t.Parallel() |
| 101 | |
| 102 | ctrl := gomock.NewController(t) |
| 103 | defer ctrl.Finish() |
| 104 | |
| 105 | withValues := []interface{}{ |
| 106 | gomock.Eq("dbname"), |
| 107 | gomock.Eq("default"), |
| 108 | gomock.Eq("driver"), |
| 109 | gomock.Eq("sqlite"), |
| 110 | } |
| 111 | |
| 112 | idle := mock_metrics.NewMockGauge(ctrl) |
| 113 | idle.EXPECT().With(withValues...).Return(idle).MinTimes(1) |
| 114 | idle.EXPECT().Set(gomock.Eq(0.0)).MinTimes(1) |
| 115 | |
| 116 | open := mock_metrics.NewMockGauge(ctrl) |
| 117 | open.EXPECT().With(withValues...).Return(open).MinTimes(1) |
| 118 | open.EXPECT().Set(gomock.Eq(2.0)).MinTimes(1) |
| 119 | |
| 120 | inUse := mock_metrics.NewMockGauge(ctrl) |
| 121 | inUse.EXPECT().With(withValues...).Return(inUse).MinTimes(1) |
| 122 | inUse.EXPECT().Set(gomock.Eq(2.0)).MinTimes(1) |
| 123 | |
| 124 | c := core.New( |
| 125 | core.WithInline("gorm.default.database", "sqlite"), |
| 126 | core.WithInline("gorm.default.dsn", "file::memory:?cache=shared"), |
| 127 | core.WithInline("gormMetrics.interval", "1ms"), |
| 128 | core.WithInline("log.level", "none"), |
| 129 | ) |
| 130 | c.ProvideEssentials() |
| 131 | c.Provide(di.Deps{func() *Gauges { |
| 132 | return NewGauges(idle, inUse, open) |
| 133 | }}) |
| 134 | c.Provide(Providers()) |
| 135 | c.AddModuleFunc(New) |
| 136 | ctx, cancel := context.WithCancel(context.Background()) |
| 137 | var ( |
| 138 | c1 *sql.Conn |
| 139 | c2 *sql.Conn |
| 140 | ) |
| 141 | c.Invoke(func(db *gorm.DB) { |
| 142 | rawSQL, _ := db.DB() |
| 143 | c1, _ = rawSQL.Conn(ctx) |
| 144 | c2, _ = rawSQL.Conn(ctx) |
| 145 | }) |
| 146 | go c.Serve(ctx) |
| 147 | <-time.After(10 * time.Millisecond) |
| 148 | cancel() |
| 149 | <-time.After(1000 * time.Millisecond) |
| 150 | c1.Close() |
| 151 | c2.Close() |
| 152 | } |
| 153 | |
| 154 | func TestProviders(t *testing.T) { |
| 155 | provider := Providers( |
nothing calls this directly
no test coverage detected