(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestRunConfigSetProviderNames(t *testing.T) { |
| 15 | if os.Getenv("OCR_TEST_CONFIG_SET") == "1" { |
| 16 | rootCmd.SetArgs(os.Args[3:]) |
| 17 | os.Exit(run()) |
| 18 | } |
| 19 | setTestHome(t, t.TempDir()) |
| 20 | configPath, err := defaultConfigPath() |
| 21 | if err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if err := saveConfig(configPath, &Config{Provider: "openai", Model: "saved-model"}); err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | tests := []struct { |
| 28 | key string |
| 29 | value string |
| 30 | code int |
| 31 | }{ |
| 32 | {"providers.openai.extra_body.model", "some-model", 1}, |
| 33 | {"custom_providers.openai.extra_body.model", "some-model", 1}, |
| 34 | {"providers.openai..url", "https://example.invalid/v1", 1}, |
| 35 | {"providers..a.url", "https://example.invalid/v1", 1}, |
| 36 | {"providers. .url", "https://example.invalid/v1", 1}, |
| 37 | {"custom_providers.anthropic..url", "https://example.invalid/v1", 1}, |
| 38 | {"provider", ".gateway", 1}, |
| 39 | {"provider", "gateway.", 1}, |
| 40 | {"provider", "gateway..v2", 1}, |
| 41 | {"provider", " ", 1}, |
| 42 | {"provider", "mimo-v2.6-flash", 0}, |
| 43 | {"providers.mimo-v2.6-flash.url", "https://example.invalid/v1", 0}, |
| 44 | {"custom_providers.mimo-v2.6-flash.protocol", "openai", 0}, |
| 45 | {"provider", "foo.api_key", 0}, |
| 46 | {"custom_providers.foo.api_key.model", "some-model", 0}, |
| 47 | } |
| 48 | for _, tt := range tests { |
| 49 | t.Run(tt.key+"/"+tt.value, func(t *testing.T) { |
| 50 | before, err := os.ReadFile(configPath) |
| 51 | if err != nil { |
| 52 | t.Fatal(err) |
| 53 | } |
| 54 | cmd := exec.Command(os.Args[0], "-test.run=^TestRunConfigSetProviderNames$", "--", "config", "set", tt.key, tt.value) |
| 55 | cmd.Env = append(os.Environ(), "OCR_TEST_CONFIG_SET=1", "OCR_NO_UPDATE=1", "OCR_ENABLE_TELEMETRY=0") |
| 56 | output, err := cmd.CombinedOutput() |
| 57 | if cmd.ProcessState == nil || cmd.ProcessState.ExitCode() != tt.code { |
| 58 | t.Fatalf("exit error = %v, want code %d; output:\n%s", err, tt.code, output) |
| 59 | } |
| 60 | after, err := os.ReadFile(configPath) |
| 61 | if err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | if tt.code != 0 && !bytes.Equal(before, after) { |
| 65 | t.Fatalf("configuration changed after rejected write: %s", after) |
| 66 | } |
| 67 | }) |
| 68 | } |
| 69 | cfg, err := loadOrCreateConfig(configPath) |
| 70 | if err != nil { |
| 71 | t.Fatal(err) |
nothing calls this directly
no test coverage detected