MCPcopy Create free account
hub / github.com/QuantumNous/new-api / TestUploadTaskPluginPreflightConflict

Function TestUploadTaskPluginPreflightConflict

controller/task_plugin_test.go:1384–1448  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1382}
1383
1384func TestUploadTaskPluginPreflightConflict(t *testing.T) {
1385 setupTaskPluginControllerTest(t)
1386 enabledFalse := false
1387 tests := []struct {
1388 name string
1389 key string
1390 enabled *bool
1391 force bool
1392 wantSuccess bool
1393 wantError string
1394 }{
1395 {
1396 name: "enabled conflict rejected",
1397 key: "preflight-reject",
1398 wantError: "channelType 50 conflicts",
1399 },
1400 {
1401 name: "force does not bypass a conflict",
1402 key: "preflight-force",
1403 force: true,
1404 wantError: "channelType 50 conflicts",
1405 },
1406 {
1407 name: "disabled skips preflight",
1408 key: "preflight-disabled",
1409 enabled: &enabledFalse,
1410 wantSuccess: true,
1411 },
1412 }
1413 for _, testCase := range tests {
1414 t.Run(testCase.name, func(t *testing.T) {
1415 cleanupTaskPluginControllerRuntime(t, testCase.key)
1416 source := taskPluginControllerChannelSource(testCase.key, "1.0.0", 50)
1417 payload := map[string]any{"source": source}
1418 if testCase.enabled != nil {
1419 payload["enabled"] = *testCase.enabled
1420 }
1421 if testCase.force {
1422 payload["force"] = true
1423 }
1424 body, err := common.Marshal(payload)
1425 require.NoError(t, err)
1426 recorder := httptest.NewRecorder()
1427 context, _ := gin.CreateTestContext(recorder)
1428 context.Request = httptest.NewRequest(http.MethodPost, "/api/plugin/task", strings.NewReader(string(body)))
1429 context.Request.Header.Set("Content-Type", "application/json")
1430
1431 UploadTaskPlugin(context)
1432
1433 if testCase.wantSuccess {
1434 assert.Contains(t, recorder.Body.String(), `"success":true`)
1435 stored, err := model.GetTaskPluginVersion(testCase.key, "")
1436 require.NoError(t, err)
1437 assert.False(t, stored.Enabled)
1438 return
1439 }
1440 assert.Contains(t, recorder.Body.String(), `"success":false`)
1441 assert.Contains(t, recorder.Body.String(), testCase.wantError)

Callers

nothing calls this directly

Calls 12

MarshalFunction · 0.92
GetTaskPluginVersionFunction · 0.92
UploadTaskPluginFunction · 0.85
SetMethod · 0.80
ContainsMethod · 0.80
CountMethod · 0.80
RunMethod · 0.65
NewReaderMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected