nephos-server 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfb43f920b7062248d844802dbd96135df959937
4
- data.tar.gz: 3e90d530f635a27f4f677c31209e45e3017f779b
3
+ metadata.gz: fe9427a82fb27f38d05a61d389a4908310c1d943
4
+ data.tar.gz: 70968b136a8816c7b91fef7c4d5c8b3b4a3c8941
5
5
  SHA512:
6
- metadata.gz: e2f24d53c42f4649b223181a5cfc35734b3cd9038ebf61f83a21b421c3f5ec4db6d4cbab6833f521207b7c6d45b44951b2a76bf65c64a3a523b05f539896cae8
7
- data.tar.gz: 05afd2f2b0e6c2ce436c52f63b7887362575ab6c38f2b45405a0f4111020cd9e8c2430d99c3f2805a8d5326cbd7d837a93b6fe86576415777cc9f28f3a6c6c1a
6
+ metadata.gz: 0dc889edb2267acd90ca1606b9f999fe70aa7bab5baeec9fd87734d06a307bcd66a0609139695549bdb6189fd51ccab8920201cfe323d4a48dc9b51839c6d7a1
7
+ data.tar.gz: 130a86745ed28082f987b755f1a42ba96d03cdf05b00cb1dc1745ffd3608d7e06bf1bcd8a6d177beb1d477635029fc6e07c27f35a41232e1d8c194e5f6c08df0
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ v0.6.9
2
+ * Fix unitary tests
3
+ * Fix binary server to handle daemons better
4
+ * Add unitary test to test the server globaly
5
+ * Log can be called from the controller
6
+
1
7
  v0.6.8
2
8
  * Update urls and links
3
9
  * Important fix for cookies
data/Rakefile CHANGED
@@ -12,15 +12,18 @@ namespace :test do
12
12
 
13
13
  desc "Unitary tests. Fasts and on the sources."
14
14
  task :test do
15
- puts
16
15
  ruby "test/test.rb"
17
16
  end
18
17
 
19
18
  desc "Functional tests. Slow, test real the features under real conditions of usage."
20
19
  task :functional do
21
- puts "!!! Important !!!".yellow
22
- puts "You have to access to internet to test the generator.".yellow
23
- puts
24
20
  ruby "test/functional.rb"
25
21
  end
22
+
23
+ namespace :functional do
24
+ task :internet do
25
+ ruby "test/functional.rb internet"
26
+ end
27
+ end
28
+
26
29
  end
data/bin/nephos-server CHANGED
@@ -51,8 +51,9 @@ begin
51
51
 
52
52
  if $kill_daemon
53
53
  raise "No Daemon started" if not Nephos::Bin::Daemon.started?
54
- puts "Daemon #{Nephos::Bin::Daemon.get_pid} stopped"
54
+ pid = Nephos::Bin::Daemon.get_pid
55
55
  Nephos::Bin::Daemon.kill!
56
+ puts "Daemon #{pid} stopped"
56
57
  exit 0
57
58
  end
58
59
  if $daemon and Nephos::Bin::Daemon.started?
@@ -29,8 +29,9 @@ module Nephos
29
29
  d = get_pid
30
30
  return false unless d
31
31
  begin
32
- Process::kill(10, d)
32
+ Process::kill(2, d)
33
33
  rescue => err
34
+ raise "Cannot kill #{d} ! (#{err.message})" if $debug
34
35
  raise "Cannot kill #{d} !"
35
36
  ensure
36
37
  File.delete(get_pid_file)
@@ -107,5 +107,9 @@ module Nephos
107
107
  end
108
108
  end
109
109
 
110
+ def log *args
111
+ Logger.write(*args)
112
+ end
113
+
110
114
  end
111
115
  end
@@ -97,7 +97,7 @@ module Nephos
97
97
  params = set_default_params(params)
98
98
  resp.status = params[:status]
99
99
  resp["Content-Type"] = params[:type]
100
- resp.body = [params[:content]]
100
+ resp.body = [params[:content] + "\n"]
101
101
  return resp
102
102
  end
103
103
 
@@ -44,6 +44,7 @@ test/logger.rb
44
44
  test/controller.rb
45
45
 
46
46
  test/functional.rb
47
+ test/functional/controller.rb
47
48
  test/functional/generator.rb
48
49
  test/functional/global.rb
49
50
  test/functional/router.rb
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ class FakeController1241525 < Nephos::Controller
4
+ DATA = %w(hello wôrld)
5
+ def log_test
6
+ Nephos::Logger.fd = File.open '/tmp/nephos_ftest.log', 'w'
7
+ log DATA
8
+ return {json: DATA}
9
+ end
10
+
11
+ def set_cookie
12
+ cookies["name"] = "value"
13
+ return {code: 200}
14
+ end
15
+ end
16
+
17
+ class TestController < Test::Unit::TestCase
18
+
19
+ FILE = "/tmp/nephos_ftest.log"
20
+
21
+ def test_log_with_one_controller
22
+ # fd = File.open(FILE, "w")
23
+ # Nephos::Logger.fd = fd
24
+ # Nephos.log %w(hello wôrld)
25
+ r = Rack::Request.new({})
26
+ c = FakeController1241525.new(r, {params: []})
27
+ c.log_test
28
+ assert_equal("hello\nwôrld\n", File.read(FILE))
29
+ File.delete FILE
30
+ end
31
+
32
+ def test_set_cookies
33
+ router = Nephos::Router.new(silent: true)
34
+ r = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/add_cookie"})
35
+ out = router.execute(r)
36
+ assert_equal "UN_COOKIE_VAUT%3A=UN+BON+MOMENT+%21", out.header["Set-Cookie"]
37
+ end
38
+
39
+ end
@@ -1,6 +1,44 @@
1
+ require 'open-uri'
2
+
1
3
  class TestGlobal < Test::Unit::TestCase
2
4
 
5
+ def start_server
6
+ stop_server
7
+ s = `./bin/nephos-server --test -d`
8
+ sleep 1
9
+ s
10
+ end
11
+
12
+ def stop_server
13
+ `./bin/nephos-server --test -k`
14
+ end
15
+
3
16
  def test_simpe_requests_on_app
17
+ start_server
18
+ r = open("http://127.0.0.1:8080/")
19
+ assert_equal "{\"list\":[],\"add\":\"/add\",\"rm\":\"/rm\"}\n", r.read
20
+ assert_equal "application/json; charset=UTF-8", r.meta["content-type"]
21
+ assert_equal "a=b", r.meta["set-cookie"]
22
+ assert_equal ["200", "OK"], r.status
23
+
24
+ r = open("http://127.0.0.1:8080/home")
25
+ assert_equal "{\"list\":[],\"add\":\"/add\",\"rm\":\"/rm\"}\n", r.read
26
+ assert_equal "application/json; charset=UTF-8", r.meta["content-type"]
27
+ assert_equal "a=b", r.meta["set-cookie"]
28
+ assert_equal ["200", "OK"], r.status
29
+
30
+ r = open("http://127.0.0.1:8080/home/")
31
+ assert_equal "{\"list\":[],\"add\":\"/add\",\"rm\":\"/rm\"}\n", r.read
32
+ assert_equal "application/json; charset=UTF-8", r.meta["content-type"]
33
+ assert_equal ["200", "OK"], r.status
34
+
35
+ r = open("http://127.0.0.1:8080/hello")
36
+ assert_equal "<html><body><h1>hello world</h1><p>lol</p></body></html>\n", r.read
37
+ assert_equal ["200", "OK"], r.status
38
+
39
+ assert_raise do open("http://127.0.0.1:8080/err500") end
40
+
41
+ stop_server
4
42
  end
5
43
 
6
44
  end
@@ -2,35 +2,45 @@ class TestNephosServerBinServer < Test::Unit::TestCase
2
2
 
3
3
  def test_daemon
4
4
  # WARNING: be sure there is no instance before running theses tests
5
+ `./bin/nephos-server --test -k`
5
6
 
6
7
  # test start and kill
7
8
  `./bin/nephos-server --test -d`
9
+ sleep 2
8
10
  assert_equal 0, $?.exitstatus
9
11
  `./bin/nephos-server --test -k`
12
+ sleep 0.5
10
13
  assert_equal 0, $?.exitstatus
11
14
 
12
15
  # test kill after killed
13
16
  `./bin/nephos-server --test -k`
17
+ sleep 0.5
14
18
  assert_equal 1, $?.exitstatus
15
19
  `./bin/nephos-server --test -k`
20
+ sleep 0.5
16
21
  assert_equal 1, $?.exitstatus
17
22
 
18
23
  # test start after killed
19
24
  `./bin/nephos-server --test -d`
25
+ sleep 2
20
26
  assert_equal 0, $?.exitstatus
21
27
 
22
28
  # test start after started
23
29
  `./bin/nephos-server --test -d`
30
+ sleep 0.5
24
31
  assert_equal 1, $?.exitstatus
25
32
  `./bin/nephos-server --test -d`
33
+ sleep 0.5
26
34
  assert_equal 1, $?.exitstatus
27
35
 
28
36
  # test kill after started N times
29
37
  `./bin/nephos-server --test -k`
38
+ sleep 0.5
30
39
  assert_equal 0, $?.exitstatus
31
40
 
32
41
  # test kill after started N times and then killed
33
42
  `./bin/nephos-server --test -k`
43
+ sleep 0.5
34
44
  assert_equal 1, $?.exitstatus
35
45
  end
36
46
 
data/test/functional.rb CHANGED
@@ -2,8 +2,13 @@ require "test/unit"
2
2
 
3
3
  require_relative "../lib/nephos-server"
4
4
 
5
- require_relative 'functional/generator'
6
- require_relative 'functional/server'
5
+ # tests global
7
6
  require_relative 'functional/global'
7
+ require_relative 'functional/server'
8
8
 
9
+ # tests on master classes
10
+ require_relative 'functional/controller'
9
11
  require_relative 'functional/router'
12
+
13
+ # test global with internet required
14
+ require_relative 'functional/generator' if ARGV[0] == "internet"
data/test/responder.rb CHANGED
@@ -111,13 +111,13 @@ class TestNephosServerResponder < Test::Unit::TestCase
111
111
  r3 = Nephos::Responder.new.render(status: 201, html: "<p>p</p>")
112
112
  assert_equal(201, r1.status)
113
113
  assert_equal("text/plain; charset=UTF-8", r1["Content-type"])
114
- assert_equal(["plaaaain"], r1.body)
114
+ assert_equal(["plaaaain\n"], r1.body)
115
115
  assert_equal(201, r2.status)
116
116
  assert_equal("application/json; charset=UTF-8", r2["Content-type"])
117
- assert_equal(["{\"data\":[1,2]}"], r2.body)
117
+ assert_equal(["{\"data\":[1,2]}\n"], r2.body)
118
118
  assert_equal(201, r3.status)
119
119
  assert_equal("text/html; charset=UTF-8", r3["Content-type"])
120
- assert_equal(["<p>p</p>"], r3.body)
120
+ assert_equal(["<p>p</p>\n"], r3.body)
121
121
  end
122
122
 
123
123
  end
data/version CHANGED
@@ -1 +1 @@
1
- 0.6.8
1
+ 0.6.9
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nephos-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
@@ -31,7 +31,7 @@ cert_chain:
31
31
  tcYkgfqUJPitIJx1RvWZpIyH5uJhRUYK3+vU9nMOxez5WbIlC1TtpByKAPMX+sht
32
32
  gib3AoIT8jh/2w==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-11-01 00:00:00.000000000 Z
34
+ date: 2015-11-06 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nomorebeer
@@ -134,6 +134,7 @@ files:
134
134
  - routes.rb
135
135
  - test/controller.rb
136
136
  - test/functional.rb
137
+ - test/functional/controller.rb
137
138
  - test/functional/generator.rb
138
139
  - test/functional/global.rb
139
140
  - test/functional/router.rb
metadata.gz.sig CHANGED
Binary file