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

Function TestUploadTaskPluginPreflightConflict

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

Source from the content-addressed store, hash-verified

844}
845
846func TestUploadTaskPluginPreflightConflict(t *testing.T) {
847 setupTaskPluginControllerTest(t)
848 enabledFalse := false
849 tests := []struct {
850 name string
851 key string
852 enabled *bool
853 force bool
854 wantSuccess bool
855 wantError string
856 }{
857 {
858 name: "enabled conflict rejected",
859 key: "preflight-reject",
860 wantError: "channelType 50 conflicts",
861 },
862 {
863 name: "force saves despite conflict",
864 key: "preflight-force",
865 force: true,
866 wantSuccess: true,
867 },
868 {
869 name: "disabled skips preflight",
870 key: "preflight-disabled",
871 enabled: &enabledFalse,
872 wantSuccess: true,
873 },
874 }
875 for _, testCase := range tests {
876 t.Run(testCase.name, func(t *testing.T) {
877 cleanupTaskPluginControllerRuntime(t, testCase.key)
878 source := taskPluginControllerChannelSource(testCase.key, "1.0.0", 50)
879 payload := map[string]any{"source": source}
880 if testCase.enabled != nil {
881 payload["enabled"] = *testCase.enabled
882 }
883 if testCase.force {
884 payload["force"] = true
885 }
886 body, err := common.Marshal(payload)
887 require.NoError(t, err)
888 recorder := httptest.NewRecorder()
889 context, _ := gin.CreateTestContext(recorder)
890 context.Request = httptest.NewRequest(http.MethodPost, "/api/plugin/task", strings.NewReader(string(body)))
891 context.Request.Header.Set("Content-Type", "application/json")
892
893 UploadTaskPlugin(context)
894
895 if testCase.wantSuccess {
896 assert.Contains(t, recorder.Body.String(), `"success":true`)
897 _, err = model.GetTaskPluginVersion(testCase.key, "")
898 require.NoError(t, err)
899 return
900 }
901 assert.Contains(t, recorder.Body.String(), `"success":false`)
902 assert.Contains(t, recorder.Body.String(), testCase.wantError)
903 assert.Contains(t, recorder.Body.String(), "kling")

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