(t *testing.T)
| 862 | } |
| 863 | |
| 864 | func 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") |
nothing calls this directly
no test coverage detected