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

Function TestUploadTaskPluginPreflightConflict

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

Source from the content-addressed store, hash-verified

862}
863
864func TestUploadTaskPluginPreflightConflict(t *testing.T) {
865 setupTaskPluginControllerTest(t)
866 enabledFalse := false
867 tests := []struct {
868 name string
869 key string
870 enabled *bool
871 force bool
872 wantSuccess bool
873 wantError string
874 }{
875 {
876 name: "enabled conflict rejected",
877 key: "preflight-reject",
878 wantError: "channelType 50 conflicts",
879 },
880 {
881 name: "force saves despite conflict",
882 key: "preflight-force",
883 force: true,
884 wantSuccess: true,
885 },
886 {
887 name: "disabled skips preflight",
888 key: "preflight-disabled",
889 enabled: &enabledFalse,
890 wantSuccess: true,
891 },
892 }
893 for _, testCase := range tests {
894 t.Run(testCase.name, func(t *testing.T) {
895 cleanupTaskPluginControllerRuntime(t, testCase.key)
896 source := taskPluginControllerChannelSource(testCase.key, "1.0.0", 50)
897 payload := map[string]any{"source": source}
898 if testCase.enabled != nil {
899 payload["enabled"] = *testCase.enabled
900 }
901 if testCase.force {
902 payload["force"] = true
903 }
904 body, err := common.Marshal(payload)
905 require.NoError(t, err)
906 recorder := httptest.NewRecorder()
907 context, _ := gin.CreateTestContext(recorder)
908 context.Request = httptest.NewRequest(http.MethodPost, "/api/plugin/task", strings.NewReader(string(body)))
909 context.Request.Header.Set("Content-Type", "application/json")
910
911 UploadTaskPlugin(context)
912
913 if testCase.wantSuccess {
914 assert.Contains(t, recorder.Body.String(), `"success":true`)
915 _, err = model.GetTaskPluginVersion(testCase.key, "")
916 require.NoError(t, err)
917 return
918 }
919 assert.Contains(t, recorder.Body.String(), `"success":false`)
920 assert.Contains(t, recorder.Body.String(), testCase.wantError)
921 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