Skip to content

Commit 568303d

Browse files
authored
Merge pull request #75 from jgnagy/feat/easier-ping-controller-use
More Options for Ping Controller usage
2 parents 0f22c5c + 52e81ce commit 568303d

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
Metatron is a Ruby library for creating [Metacontroller](https://metacontroller.github.io/metacontroller/)-based custom Kubernetes controllers.
44

5-
The intention is to make it as easy as possible to use Ruby to manage [custom resources](https://kubernetes.io/docs/concepts/api-extension/custom-resources/) within your Kubernetes infrastructure. No Golang required!
5+
The intention is to make it as easy as possible to use Ruby to manage [custom resources](https://kubernetes.io/docs/concepts/api-extension/custom-resources/) within your Kubernetes infrastructure. No Golang required! Use simple, Rack-based controllers to provide the logic for your custom resources. Metatron templates provide a most Kubernetes boilerplate code for you, so you can focus on the logic that enables your custom resources to do what you need them to do.
66

77
For more information, see the [Metatron Wiki on GitHub](https://github.com/jgnagy/metatron/wiki)!
88

99
For help on how to get started, take a look at the [User Guide](https://github.com/jgnagy/metatron/wiki/User-Guide) in the Wiki!
10+
11+
## Contributing
12+
13+
If you're interested in contributing to Metatron, please see the [Contributing Guide](CONTRIBUTING.md) in the repository! Be sure to check out the [Code of Conduct](CODE_OF_CONDUCT.md) as well!

lib/metatron/controllers/ping.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ module Controllers
66
class Ping
77
RESPONSE = { status: "up" }.to_json
88

9+
class << self
10+
def call(env) = new.call(env)
11+
end
12+
913
def call(env)
1014
req = Rack::Request.new(env)
1115

spec/metatron/controllers/ping_spec.rb

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,61 @@
66
RSpec.describe Metatron::Controllers::Ping do
77
include Rack::Test::Methods
88

9-
let(:app) { Rack::Lint.new(described_class.new) }
9+
describe "as a class" do
10+
let(:app) { Rack::Lint.new(described_class) }
1011

11-
it "returns a 200 status" do
12-
get "/"
13-
expect(last_response.status).to eq(200)
14-
end
12+
it "returns a 200 status" do
13+
get "/"
14+
expect(last_response.status).to eq(200)
15+
end
1516

16-
it "returns a JSON response body" do
17-
get "/"
18-
expect(last_response.body).to eq({ status: "up" }.to_json)
19-
end
17+
it "returns a JSON response body" do
18+
get "/"
19+
expect(last_response.body).to eq({ status: "up" }.to_json)
20+
end
2021

21-
it "responds with JSON content-type header" do
22-
get "/"
23-
expect(last_response.headers["content-type"]).to eq("application/json")
24-
end
22+
it "responds with JSON content-type header" do
23+
get "/"
24+
expect(last_response.headers["content-type"]).to eq("application/json")
25+
end
2526

26-
it "returns a 403 status for invalid request methods" do
27-
post "/"
28-
expect(last_response.status).to eq(403)
27+
it "returns a 403 status for invalid request methods" do
28+
post "/"
29+
expect(last_response.status).to eq(403)
30+
end
31+
32+
it "returns allowed request methods on options request" do
33+
options "/"
34+
expect(last_response.headers["access-control-allow-methods"]).to eq(["GET"])
35+
end
2936
end
3037

31-
it "returns allowed request methods on options request" do
32-
options "/"
33-
expect(last_response.headers["access-control-allow-methods"]).to eq(["GET"])
38+
describe "as an instance" do
39+
let(:app) { Rack::Lint.new(described_class.new) }
40+
41+
it "returns a 200 status" do
42+
get "/"
43+
expect(last_response.status).to eq(200)
44+
end
45+
46+
it "returns a JSON response body" do
47+
get "/"
48+
expect(last_response.body).to eq({ status: "up" }.to_json)
49+
end
50+
51+
it "responds with JSON content-type header" do
52+
get "/"
53+
expect(last_response.headers["content-type"]).to eq("application/json")
54+
end
55+
56+
it "returns a 403 status for invalid request methods" do
57+
post "/"
58+
expect(last_response.status).to eq(403)
59+
end
60+
61+
it "returns allowed request methods on options request" do
62+
options "/"
63+
expect(last_response.headers["access-control-allow-methods"]).to eq(["GET"])
64+
end
3465
end
3566
end

0 commit comments

Comments
 (0)