Skip to content

Commit 6c6e632

Browse files
committed
test: Create vscode_package_test.rb
1 parent 84996f3 commit 6c6e632

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "serverkit/resources/vscode_package"
5+
6+
class Serverkit::Resources::VscodePackageTest < Minitest::Test
7+
ATTRIBUTES = {"name" => "test-package"}
8+
ATTRIBUTES_WITH_VERSION = {"name" => "test-package", "version" => "1.2.3"}
9+
10+
def setup
11+
@resource = Serverkit::Resources::VscodePackage.new({}, ATTRIBUTES)
12+
@resource_with_version = Serverkit::Resources::VscodePackage.new({}, ATTRIBUTES_WITH_VERSION)
13+
end
14+
15+
def test_resource_instance
16+
assert_instance_of Serverkit::Resources::VscodePackage, @resource
17+
assert_instance_of Serverkit::Resources::VscodePackage, @resource_with_version
18+
end
19+
20+
def test_apply
21+
@resource.stub :run_command, ->(cmd) { cmd } do
22+
assert_equal("code --install-extension test-package", @resource.apply)
23+
end
24+
@resource_with_version.stub :run_command, ->(cmd) { cmd } do
25+
assert_equal("code --install-extension test-package@1.2.3", resource_with_version.apply)
26+
end
27+
end
28+
29+
def test_check
30+
@resource.stub :check_command, ->(cmd) { cmd } do
31+
assert_equal("code --list-extensions --show-versions | grep -E '^test-package@'", @resource.check)
32+
end
33+
@resource_with_version.stub :check_command, ->(cmd) { cmd } do
34+
assert_equal("code --list-extensions --show-versions | grep -E '^test-package@1.2.3$'", resource_with_version.check)
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)