Files
roux/test/Roux/ConfigSpec.hs
T

56 lines
2.4 KiB
Haskell

module Roux.ConfigSpec (spec) where
import System.FilePath ((</>))
import System.IO.Temp (withSystemTempDirectory)
import Test.Hspec (Spec, describe, expectationFailure, it, shouldBe)
import Roux.Config
spec :: Spec
spec = describe "loadConfig" $ do
it "returns Nothing config when file doesn't exist" $ do
result <- loadConfig "/tmp/nonexistent-config-file-for-roux-test.yaml"
result `shouldBe` Right (RouxConfig Nothing)
it "parses a minimal config with api_key" $ do
withSystemTempDirectory "roux-test" $ \dir -> do
let path = dir </> "config.yaml"
writeFile path "anthropic:\n api_key: sk-test-123\n"
result <- loadConfig path
case result of
Right (RouxConfig (Just ac)) -> do
acApiKey ac `shouldBe` "sk-test-123"
acBaseUrl ac `shouldBe` Nothing
acModel ac `shouldBe` Nothing
_ -> expectationFailure "Expected Right config"
it "parses a full config with all fields" $ do
withSystemTempDirectory "roux-test" $ \dir -> do
let path = dir </> "config.yaml"
writeFile path "anthropic:\n api_key: sk-test-456\n base_url: http://localhost:11434/v1\n model: local-model\n"
result <- loadConfig path
case result of
Right (RouxConfig (Just ac)) -> do
acApiKey ac `shouldBe` "sk-test-456"
acBaseUrl ac `shouldBe` Just "http://localhost:11434/v1"
acModel ac `shouldBe` Just "local-model"
_ -> expectationFailure "Expected Right config"
it "returns Left for malformed YAML" $ do
withSystemTempDirectory "roux-test" $ \dir -> do
let path = dir </> "config.yaml"
writeFile path "{{{{ invalid yaml }}}}\n"
result <- loadConfig path
case result of
Left _ -> pure () -- expected
Right _ -> expectationFailure "Expected Left error"
it "returns Left when api_key is missing" $ do
withSystemTempDirectory "roux-test" $ \dir -> do
let path = dir </> "config.yaml"
writeFile path "anthropic:\n model: foo\n"
result <- loadConfig path
case result of
Left _ -> pure () -- expected
Right _ -> expectationFailure "Expected Left error"