Merge pull request #220 from koic/fix_resource_embedded_not_setting_resource_in_initialize
Fix `Resource::Embedded` not setting `@resource` in `initialize`
This commit is contained in:
commit
248c1ec532
2 changed files with 108 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ module MCP
|
|||
attr_reader :resource, :annotations
|
||||
|
||||
def initialize(resource:, annotations: nil)
|
||||
@resource = resource
|
||||
@annotations = annotations
|
||||
end
|
||||
|
||||
|
|
|
|||
107
test/mcp/resource/embedded_test.rb
Normal file
107
test/mcp/resource/embedded_test.rb
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
module MCP
|
||||
class Resource
|
||||
class EmbeddedTest < ActiveSupport::TestCase
|
||||
test "initializes with resource" do
|
||||
resource = Resource.new(
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
description: "a test resource",
|
||||
)
|
||||
embedded = Resource::Embedded.new(resource: resource)
|
||||
|
||||
assert_equal resource, embedded.resource
|
||||
end
|
||||
|
||||
test "initializes with resource and annotations" do
|
||||
resource = Resource.new(
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
description: "a test resource",
|
||||
)
|
||||
annotations = { audience: ["user"], priority: 1.0 }
|
||||
embedded = Resource::Embedded.new(resource: resource, annotations: annotations)
|
||||
|
||||
assert_equal resource, embedded.resource
|
||||
assert_equal annotations, embedded.annotations
|
||||
end
|
||||
|
||||
test "initializes with annotations as nil when not provided" do
|
||||
resource = Resource.new(
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
description: "a test resource",
|
||||
)
|
||||
embedded = Resource::Embedded.new(resource: resource)
|
||||
|
||||
assert_nil embedded.annotations
|
||||
end
|
||||
|
||||
test "#to_h returns hash with resource data when annotations is nil" do
|
||||
resource = Resource.new(
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
description: "a test resource",
|
||||
)
|
||||
embedded = Resource::Embedded.new(resource: resource)
|
||||
|
||||
expected = {
|
||||
resource: {
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
description: "a test resource",
|
||||
},
|
||||
}
|
||||
|
||||
assert_equal expected, embedded.to_h
|
||||
end
|
||||
|
||||
test "#to_h returns hash with resource and annotations when both are present" do
|
||||
resource = Resource.new(
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
description: "a test resource",
|
||||
)
|
||||
annotations = { audience: ["user"], priority: 1.0 }
|
||||
embedded = Resource::Embedded.new(resource: resource, annotations: annotations)
|
||||
|
||||
expected = {
|
||||
resource: {
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
description: "a test resource",
|
||||
},
|
||||
annotations: { audience: ["user"], priority: 1.0 },
|
||||
}
|
||||
|
||||
assert_equal expected, embedded.to_h
|
||||
end
|
||||
|
||||
test "#to_h handles resource with all optional fields" do
|
||||
resource = Resource.new(
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
title: "Test Resource",
|
||||
description: "a test resource",
|
||||
mime_type: "text/plain",
|
||||
)
|
||||
embedded = Resource::Embedded.new(resource: resource)
|
||||
|
||||
expected = {
|
||||
resource: {
|
||||
uri: "file:///test.txt",
|
||||
name: "test_resource",
|
||||
title: "Test Resource",
|
||||
description: "a test resource",
|
||||
mimeType: "text/plain",
|
||||
},
|
||||
}
|
||||
|
||||
assert_equal expected, embedded.to_h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue