(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestRequirePluginEnabled(t *testing.T) { |
| 14 | db := testdb.NewDBWithDefaultUser(t) |
| 15 | conf := &model.PluginConf{ |
| 16 | ID: 1, |
| 17 | UserID: 1, |
| 18 | Enabled: true, |
| 19 | } |
| 20 | db.CreatePluginConf(conf) |
| 21 | |
| 22 | g := gin.New() |
| 23 | |
| 24 | mux := g.Group("/", requirePluginEnabled(1, db)) |
| 25 | |
| 26 | mux.GET("/", func(c *gin.Context) { |
| 27 | c.Status(200) |
| 28 | }) |
| 29 | |
| 30 | getCode := func() int { |
| 31 | r := httptest.NewRequest("GET", "/", nil) |
| 32 | w := httptest.NewRecorder() |
| 33 | g.ServeHTTP(w, r) |
| 34 | return w.Code |
| 35 | } |
| 36 | |
| 37 | assert.Equal(t, 200, getCode()) |
| 38 | |
| 39 | conf.Enabled = false |
| 40 | db.UpdatePluginConf(conf) |
| 41 | assert.Equal(t, 400, getCode()) |
| 42 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…