client_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package lsp
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/charmbracelet/crush/internal/config"
  6. "github.com/charmbracelet/crush/internal/env"
  7. )
  8. func TestClient(t *testing.T) {
  9. ctx := context.Background()
  10. // Create a simple config for testing
  11. cfg := config.LSPConfig{
  12. Command: "$THE_CMD", // Use echo as a dummy command that won't fail
  13. Args: []string{"hello"},
  14. FileTypes: []string{"go"},
  15. Env: map[string]string{},
  16. }
  17. // Test creating a powernap client - this will likely fail with echo
  18. // but we can still test the basic structure
  19. client, err := New(ctx, "test", cfg, config.NewEnvironmentVariableResolver(env.NewFromMap(map[string]string{
  20. "THE_CMD": "echo",
  21. })))
  22. if err != nil {
  23. // Expected to fail with echo command, skip the rest
  24. t.Skipf("Powernap client creation failed as expected with dummy command: %v", err)
  25. return
  26. }
  27. // If we get here, test basic interface methods
  28. if client.GetName() != "test" {
  29. t.Errorf("Expected name 'test', got '%s'", client.GetName())
  30. }
  31. if !client.HandlesFile("test.go") {
  32. t.Error("Expected client to handle .go files")
  33. }
  34. if client.HandlesFile("test.py") {
  35. t.Error("Expected client to not handle .py files")
  36. }
  37. // Test server state
  38. client.SetServerState(StateReady)
  39. if client.GetServerState() != StateReady {
  40. t.Error("Expected server state to be StateReady")
  41. }
  42. // Clean up - expect this to fail with echo command
  43. if err := client.Close(t.Context()); err != nil {
  44. // Expected to fail with echo command
  45. t.Logf("Close failed as expected with dummy command: %v", err)
  46. }
  47. }