stella 0.7.3.002 → 0.7.4.001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +0,0 @@
1
-
2
-
3
- class Stella::Client
4
-
5
- class ResponseModifier; end
6
- class Repeat < ResponseModifier;
7
- attr_accessor :times
8
- def initialize(times)
9
- @times = times
10
- end
11
- end
12
- class Quit < ResponseModifier;
13
- attr_accessor :message
14
- def initialize(msg=nil)
15
- @message = msg
16
- end
17
- end
18
- class Fail < Quit; end
19
-
20
- end
data/lib/stella/config.rb DELETED
@@ -1,87 +0,0 @@
1
-
2
-
3
- class Stella::Config < Storable
4
- include Gibbler::Complex
5
-
6
- field :source
7
- field :apikey
8
- field :secret
9
-
10
- # Returns true when the current config matches the default config
11
- def default?; to_hash.gibbler == DEFAULT_CONFIG_HASH; end
12
-
13
- def self.each_path(&blk)
14
- [PROJECT_PATH, USER_PATH].each do |path|
15
- Stella.ld "Loading #{path}"
16
- blk.call(path) if File.exists? path
17
- end
18
- end
19
-
20
- def self.refresh
21
- conf = {}
22
- Stella::Config.each_path do |path|
23
- tmp = YAML.load_file path
24
- conf.merge! tmp if tmp
25
- end
26
- from_hash conf
27
- end
28
-
29
- def self.init
30
- raise AlreadyInitialized, PROJECT_PATH if File.exists? PROJECT_PATH
31
- dir = File.dirname USER_PATH
32
- Dir.mkdir(dir, 0700) unless File.exists? dir
33
- unless File.exists? USER_PATH
34
- Stella.li "Creating #{USER_PATH} (Add your credentials here)"
35
- Stella::Utils.write_to_file(USER_PATH, DEFAULT_CONFIG, 'w', 0600)
36
- end
37
-
38
- dir = File.dirname PROJECT_PATH
39
- Dir.mkdir(dir, 0700) unless File.exists? dir
40
-
41
- Stella.li "Creating #{PROJECT_PATH}"
42
- Stella::Utils.write_to_file(PROJECT_PATH, 'target:', 'w', 0600)
43
- end
44
-
45
- def self.blast
46
- if File.exists? USER_PATH
47
- Stella.li "Blasting #{USER_PATH}"
48
- FileUtils.rm_rf File.dirname(USER_PATH)
49
- end
50
- if File.exists? PROJECT_PATH
51
- Stella.li "Blasting #{PROJECT_PATH}"
52
- FileUtils.rm_rf File.dirname(PROJECT_PATH)
53
- end
54
- end
55
-
56
-
57
- private
58
-
59
- def self.find_project_config
60
- dir = Dir.pwd.split File::SEPARATOR
61
- path = nil
62
- while !dir.empty?
63
- tmp = File.join(dir.join(File::SEPARATOR), DIR_NAME, 'config')
64
- Stella.ld " -> looking for #{tmp}"
65
- path = tmp and break if File.exists? tmp
66
- dir.pop
67
- end
68
- path ||= File.join(Dir.pwd, DIR_NAME, 'config')
69
- path
70
- end
71
-
72
-
73
- unless defined?(DIR_NAME)
74
- DIR_NAME = Stella.sysinfo.os == :windows ? 'Stella' : '.stella'
75
- USER_PATH = File.join(Stella.sysinfo.home, DIR_NAME, 'config')
76
- PROJECT_PATH = Stella::Config.find_project_config
77
- DEFAULT_CONFIG = <<CONF
78
- apikey: ''
79
- secret: ''
80
- remote: stella.solutious.com:443
81
- CONF
82
- DEFAULT_CONFIG_HASH = YAML.load(DEFAULT_CONFIG).gibbler
83
- end
84
-
85
- class AlreadyInitialized < Stella::Error; end
86
- end
87
-
@@ -1,15 +0,0 @@
1
- module Stella::Data::HTTP
2
- class Body < Storable
3
- include Gibbler::Complex
4
-
5
- field :content_type
6
- field :form_param
7
- field :content
8
-
9
- def has_content?
10
- !@content.nil?
11
- end
12
-
13
- end
14
-
15
- end
@@ -1,129 +0,0 @@
1
-
2
-
3
- module Stella::Data::HTTP
4
- class Request < Storable
5
- include Gibbler::Complex
6
- include Stella::Data::Helpers
7
-
8
- # A hash containing blocks to be executed depending on the HTTP response status.
9
- # The hash keys are numeric HTTP Status Codes.
10
- #
11
- # 200 => { ... }
12
- # 304 => { ... }
13
- # 500 => { ... }
14
- #
15
- attr_accessor :response_handler
16
-
17
- field :desc
18
- field :header
19
- field :uri
20
- field :wait
21
- field :params
22
- field :body
23
- field :http_method
24
- field :http_version
25
- field :content_type
26
- field :http_auth
27
-
28
- def has_body?
29
- !@body.nil?
30
- end
31
-
32
- def initialize (method, uri_str, version="1.1", &definition)
33
- @uri = uri_str
34
- @http_method, @http_version = method, version
35
- @headers, @params, @response_handler = {}, {}, {}
36
- @resources = {}
37
- @wait = 0
38
- @desc = "Request"
39
- @body = Stella::Data::HTTP::Body.new
40
- instance_eval &definition unless definition.nil?
41
- end
42
-
43
- def auth(user=nil, pass=nil, kind=:basic)
44
- @http_auth ||= Stella::Testplan::Usecase::Auth.new
45
- @http_auth.user, @http_auth.pass, @http_auth.kind = user, pass, kind
46
- end
47
-
48
- def desc(*args)
49
- @desc = args.first unless args.empty?
50
- @desc
51
- end
52
-
53
- def content_type(*args)
54
- @content_type = args.first unless args.empty?
55
- @content_type
56
- end
57
-
58
- def wait(*args)
59
- @wait = args.first unless args.empty?
60
- @wait
61
- end
62
- alias_method :sleep, :wait
63
-
64
- def headers(*args)
65
- unless args.empty?
66
- h = Hash === args[0] ? args[0] : {args[0]=> args[1]}
67
- @headers.merge! h unless h.empty?
68
- end
69
- @headers
70
- end
71
- alias_method :header, :headers
72
-
73
- # Set a resource key value pair in the get, post block.
74
- # These will be process later in Stella::Client
75
- def set(*args)
76
- unless args.empty?
77
- h = Hash === args[0] ? args[0] : {args[0]=> args[1]}
78
- @resources.merge! h unless h.empty?
79
- end
80
- @resources
81
- end
82
- alias_method :resources, :set
83
-
84
- def params(*args)
85
- unless args.empty?
86
- h = Hash === args[0] ? args[0] : {args[0]=> args[1]}
87
- @params.merge! h unless h.empty?
88
- end
89
- @params
90
- end
91
- alias_method :param, :params
92
-
93
- def response(*args, &definition)
94
- if definition.nil?
95
- @response_handler
96
- else
97
- args << /.+/ if args.empty?
98
- args.each do |status|
99
- @response_handler[status] = definition
100
- end
101
- end
102
- end
103
-
104
- # +content+ can be literal content or a file path
105
- def body(*args)
106
- return @body if args.empty?
107
- @body = args.first
108
- end
109
-
110
- def inspect
111
- str = "%s %s" % [http_method, uri.to_s, http_version]
112
- #str << $/ + headers.join($/) unless headers.empty?
113
- #str << $/ + $/ + body.to_s if body
114
- str
115
- end
116
-
117
- def to_s
118
- str = "%s %s" % [http_method, uri.to_s, http_version]
119
- str
120
- end
121
-
122
- def cookies
123
- return [] if !header.is_a?(Hash) || header[:Cookie].empty?
124
- header[:Cookie]
125
- end
126
-
127
- end
128
-
129
- end
@@ -1,92 +0,0 @@
1
-
2
-
3
- module Stella::Data::HTTP
4
-
5
- class Response < Storable
6
- include Gibbler::Complex
7
-
8
- attr_reader :raw_data
9
-
10
- field :time => DateTime
11
- field :client_ip => String
12
- field :server_ip => String
13
- field :header => String
14
- field :body => String
15
- field :status => String
16
- field :message => String
17
- field :http_version => String
18
-
19
- def initialize(raw_data=nil)
20
- @raw_data = raw_data
21
- parse(@raw_data)
22
- end
23
-
24
- def parse(raw)
25
- return unless raw
26
- @status, @http_version, @message, @header, @body = HTTPUtil::parse_http_response(raw)
27
- end
28
-
29
- def has_body?
30
- !@body.nil? && !@body.empty?
31
- end
32
- def has_request?
33
- false
34
- end
35
- def has_response?
36
- false
37
- end
38
-
39
-
40
- def body
41
- return nil unless @body
42
- #TODO: Move to HTTPResponse::Body.to_s
43
- if is_binary?
44
- "[skipping binary content]"
45
- elsif is_gzip?
46
- #require 'zlib'
47
- #Zlib::Inflate.inflate(@body)
48
- "[skipping gzip content]"
49
- else
50
- @body
51
- end
52
- end
53
-
54
- def headers
55
- headers = []
56
- header.each_pair do |n,v|
57
- headers << [n.to_s.gsub('_', '-'), v[0]]
58
- end
59
- headers
60
- end
61
-
62
- def is_binary?
63
- (!is_text?) == true
64
- end
65
-
66
- def is_text?
67
- (!header[:Content_Type].nil? && (header[:Content_Type][0].is_a? String) && header[:Content_Type][0][/text/] != nil)
68
- end
69
-
70
- def is_gzip?
71
- (!header[:Content_Encoding].nil? && (header[:Content_Encoding][0].is_a? String) && header[:Content_Encoding][0][/gzip/] != nil)
72
- end
73
-
74
- def inspect
75
- str = "HTTP/%s %s (%s)" % [@http_version, @status, @message]
76
- str << $/ + headers.join($/)
77
- str << $/ + $/ + body if body
78
- str
79
- end
80
-
81
- def to_s
82
- str = "%s: HTTP/%s %s (%s)" % [time.strftime(NICE_TIME_FORMAT), @http_version, @status, @message]
83
- str
84
- end
85
-
86
-
87
- def cookies
88
- return [] unless header.is_a?(Array) && !header[:Set_Cookie].empty?
89
- header[:Set_Cookie]
90
- end
91
- end
92
- end
@@ -1,20 +0,0 @@
1
-
2
-
3
- module Stella
4
- class Error < RuntimeError
5
- def initialize(obj=nil); @obj = obj; end
6
- def message; "#{self.class}: #{@obj}"; end
7
- end
8
-
9
- class WackyRatio < Stella::Error
10
- end
11
-
12
- class WackyDuration < Stella::Error
13
- end
14
-
15
- class InvalidOption < Stella::Error
16
- end
17
-
18
- class NoHostDefined < Stella::Error
19
- end
20
- end
data/lib/stella/mixins.rb DELETED
@@ -1,5 +0,0 @@
1
-
2
- require 'stella/mixins/time'
3
- require 'stella/mixins/string'
4
- require 'stella/mixins/numeric'
5
- require 'stella/mixins/thread'
@@ -1,24 +0,0 @@
1
-
2
-
3
- class Numeric
4
- include Time::Units
5
- # TODO: Use 1024?
6
- def to_bytes
7
- args = case self.abs.to_i
8
- when 0..1000
9
- [(self).to_s, 'B']
10
- when (1000)..(1000**2)
11
- [(self / 1000.to_f).to_s, 'KB']
12
- when (1000**2)..(1000**3)
13
- [(self / (1000**2).to_f).to_s, 'MB']
14
- when (1000**3)..(1000**4)
15
- [(self / (1000**3).to_f).to_s, 'GB']
16
- when (1000**4)..(1000**6)
17
- [(self / (1000**4).to_f).to_s, 'TB']
18
- else
19
- [self, 'B']
20
- end
21
- '%3.2f%s' % args
22
- end
23
- end
24
-
@@ -1,16 +0,0 @@
1
- # Assumes Time::Units and Numeric mixins are available.
2
-
3
- class String
4
-
5
- def in_seconds
6
- # "60m" => ["60", "m"]
7
- q,u = self.scan(/([\d\.]+)([s,m,h])?/).flatten
8
- q &&= q.to_f and u ||= 's'
9
- q &&= q.in_seconds(u)
10
- end
11
-
12
- end
13
-
14
- class MatchData
15
- include Gibbler::String
16
- end
@@ -1,6 +0,0 @@
1
-
2
-
3
- class Thread
4
- extend Attic
5
- attic :stats
6
- end
@@ -1,75 +0,0 @@
1
- #encoding: utf-8
2
-
3
- $KCODE = "u" if RUBY_VERSION =~ /^1.8/
4
-
5
- class Time
6
- module Units
7
- PER_MICROSECOND = 0.000001.freeze
8
- PER_MILLISECOND = 0.001.freeze
9
- PER_MINUTE = 60.0.freeze
10
- PER_HOUR = 3600.0.freeze
11
- PER_DAY = 86400.0.freeze
12
-
13
- def microseconds() seconds * PER_MICROSECOND end
14
- def milliseconds() seconds * PER_MILLISECOND end
15
- def seconds() self end
16
- def minutes() seconds * PER_MINUTE end
17
- def hours() seconds * PER_HOUR end
18
- def days() seconds * PER_DAY end
19
- def weeks() seconds * PER_DAY * 7 end
20
- def years() seconds * PER_DAY * 365 end
21
-
22
- def in_years() seconds / PER_DAY / 365 end
23
- def in_weeks() seconds / PER_DAY / 7 end
24
- def in_days() seconds / PER_DAY end
25
- def in_hours() seconds / PER_HOUR end
26
- def in_minutes() seconds / PER_MINUTE end
27
- def in_milliseconds() seconds / PER_MILLISECOND end
28
- def in_microseconds() seconds / PER_MICROSECOND end
29
-
30
- def in_seconds(u=nil)
31
- case u.to_s
32
- when /\A(y)|(years?)\z/
33
- years
34
- when /\A(w)|(weeks?)\z/
35
- weeks
36
- when /\A(d)|(days?)\z/
37
- days
38
- when /\A(h)|(hours?)\z/
39
- hours
40
- when /\A(m)|(minutes?)\z/
41
- minutes
42
- when /\A(ms)|(milliseconds?)\z/
43
- milliseconds
44
- when /\A(us)|(microseconds?)|(μs)\z/
45
- microseconds
46
- else
47
- self
48
- end
49
- end
50
-
51
- ## JRuby doesn't like using instance_methods.select here.
52
- ## It could be a bug or something quirky with Attic
53
- ## (although it works in 1.8 and 1.9). The error:
54
- ##
55
- ## lib/attic.rb:32:in `select': yield called out of block (LocalJumpError)
56
- ## lib/stella/mixins/numeric.rb:24
57
- ##
58
- ## Create singular methods, like hour and day.
59
- # instance_methods.select.each do |plural|
60
- # singular = plural.to_s.chop
61
- # alias_method singular, plural
62
- # end
63
-
64
- alias_method :ms, :milliseconds
65
- alias_method :'μs', :microseconds
66
- alias_method :second, :seconds
67
- alias_method :minute, :minutes
68
- alias_method :hour, :hours
69
- alias_method :day, :days
70
- alias_method :week, :weeks
71
- alias_method :year, :years
72
-
73
- end
74
- end
75
-