Skip to content

Commit 41daf04

Browse files
authored
Merge pull request #4 from serverkit/update-README
docs: Update `README.md` / test: Add tests for `Serverkit::Resources::VscodePackage`
2 parents f65eb82 + 83769bd commit 41daf04

File tree

4 files changed

+75
-11
lines changed

4 files changed

+75
-11
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,38 @@
55

66
[Serverkit](https://github.com/serverkit/serverkit) plug-in for [VSCode](https://code.visualstudio.com/).
77

8-
## Install
8+
## Installation
99

1010
```rb
1111
# Gemfile
1212
gem "serverkit-vscode"
1313
```
1414

15+
## Usage
16+
17+
### Prerequisites
18+
19+
- Ensure you have [serverkit](https://github.com/serverkit/serverkit) gem installed
20+
- Ensure you have [VSCode CLI](https://code.visualstudio.com/docs/configure/command-line) installed on your system
21+
22+
### Basic Example
23+
24+
Create a recipe file that uses the vscode resources:
25+
26+
```yaml
27+
# recipe.yml
28+
resources:
29+
# Install GitHub Copilot extension
30+
- type: vscode_package
31+
name: github.copilot
32+
```
33+
34+
Then apply your recipe with Serverkit:
35+
36+
```console
37+
$ serverkit apply recipe.yml
38+
```
39+
1540
## Resource
1641

1742
### vscode_package

Rakefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
# frozen_string_literal: true
2+
13
require "bundler/gem_tasks"
2-
require "rake/testtask"
4+
require "minitest/test_task"
35

4-
Rake::TestTask.new(:test) do |t|
5-
t.libs << "test"
6-
t.libs << "lib"
7-
t.test_files = FileList["test/**/*_test.rb"]
8-
end
6+
Minitest::TestTask.create
97

10-
task :default => :test
8+
task default: :test

serverkit-vscode.gemspec

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ Gem::Specification.new do |spec|
2020

2121
# Specify which files should be added to the gem when it is released.
2222
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23+
gemspec = File.basename(__FILE__)
24+
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
25+
ls.readlines("\x0", chomp: true).reject do |f|
26+
(f == gemspec) ||
27+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
28+
end
2529
end
2630
spec.bindir = "exe"
27-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
2832
spec.require_paths = ["lib"]
2933

3034
spec.add_runtime_dependency "serverkit"
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 [email protected]", @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 '^[email protected]$'", @resource_with_version.check)
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)