tng-gtk-utils 0.1.1 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3fd1b1e17d4ed800b02914df72e2a001bb68131571e693957ebea2970f48ac3
4
- data.tar.gz: 5759d3e439d81b341db6b5fe549b997a40279e75b31455970b8acc7a00e0301b
3
+ metadata.gz: 06432f9bb54220cd63a3edb58ac8d8d297ed8efbe5cc2cd38e38d25f8221a6a1
4
+ data.tar.gz: 570751a38e231e9717579bcfe7fb70a01282744d3ef60922e7312dc6c7697839
5
5
  SHA512:
6
- metadata.gz: 519089a97c506902f17b681f8c177b526575a2a1143bb3a6aa87e66c042e7571a77942f1d9f1a4a7cf6e4ee5236301e9a53a7db0022a14b9bbfb2d2cfbfacfb1
7
- data.tar.gz: 8591a9e3fbbe454849fe8ade24f2914aac5d6395c40e8e912d96b672e39e2526706ab8d00e25822d05c3ec1dde1d57268e1c1b8a0fa67a338a73b2e8b2d9c08c
6
+ metadata.gz: faa209d904dfa9cc449ec0f7a1740200f9e0279e42bc8ced8f44acdaa21c5c2ed35734b060e0472d5ca7e6ee37032f01fd6a5ac09b23d451c48eb52aacae04a1
7
+ data.tar.gz: 64b48f6d6f41dc44ce799e929a1f1adc1484dfaee48b1b87816ae4b6c254e022dd9b471eacbb161efe16fabb4368f68fca7f5eab1cd698e576fd73c854d7a587
data/README.md CHANGED
@@ -37,12 +37,71 @@ Logger.new(logdev, formatter: proc {|severity, datetime, progname, msg|
37
37
 
38
38
  It should also support a `LOGLEVEL` variable that may assume one of the usual values `debug`, `info`, `warning`, `error`, `fatal` or `unknown` (defaults to `warning`, so only logging messages marked as `unknown`, `fatal`, `error` or `warning` are shown).
39
39
 
40
+ #### Example
41
+ ```ruby
42
+ ```
43
+
44
+ #### Dependencies
45
+
40
46
  ### Cache
41
47
  The first ...
48
+
49
+ The `Tng::Gtk::Utils`' cache API is detailled next.
50
+
51
+ To use this, you need to require this library (`tng/gtk/utils`):
52
+
53
+ ```ruby
54
+ require `tng/gtk/utils'
55
+ ```
56
+
57
+ Then, in the `module` or `class` you want to use cache, just extend the module:
58
+ ```ruby
59
+ extend Tng::Gtk::Utils
60
+ ```
61
+
62
+ Whenever you want to cache an `Hash`, just use the `cache` macro (or `module method`):
63
+ ```ruby
64
+ cache {uuid: '4345444a-d659-4843-a618-ea43b8a1f9ba', whatever: 'else'}.to_json
65
+ ```
66
+ For checking if we've got some `UUID` cached, just use the `cached?` macro:
67
+
68
+ ```ruby
69
+ x = cached? '4345444a-d659-4843-a618-ea43b8a1f9ba'
70
+ ```
71
+
72
+ #### Example
73
+ ```ruby
74
+ require 'json'
75
+ require `tng/gtk/utils'
76
+
77
+ class Fetch
78
+ extend Tng::Gtk::Utils
79
+
80
+ class << self
81
+ def call(params)
82
+ do_validation_stuff
83
+
84
+ cached = cached? params[:uuid] # now check if we've got this cached
85
+ return JSON.parse(cached, symbolize_names: :true) if cached
86
+
87
+ real_value = fetch_real_value # if here, then it's not cached: fetch real value
88
+ cache real_value.to_json # and cache it for next time (and return it)
89
+ end
90
+ end
91
+ end
92
+ ```
93
+
94
+ #### Dependencies
42
95
  uses Logger
43
96
 
44
97
  ### Fetch
45
- remote
98
+ The `Fetch` class works very much like Euby-on-Rails' `ActiveModel` gem, without all the complexities around it.
99
+
100
+ #### Example
101
+ ```ruby
102
+ ```
103
+
104
+ #### Dependencies
46
105
  uses Cache and Logger
47
106
 
48
107
  ## Installing
@@ -32,73 +32,73 @@
32
32
  # encoding: utf-8
33
33
  # frozen_string_literal: true
34
34
  require 'redis'
35
+ require 'json'
36
+ require 'tng/gtk/utils/logger'
35
37
 
36
38
  module Tng
37
39
  module Gtk
38
40
  module Utils
39
- class Cache
40
-
41
- class RedisCache
42
- class << self
43
- attr_accessor :store
44
- end
45
-
46
- def store=(value) self.class.store = value end
47
- def store() self.class.store end
41
+ class RedisCache
42
+ class << self; attr_accessor :store; end
43
+ #def store=(value) self.class.store = value end
44
+ #def store() self.class.store end
48
45
 
49
- begin
50
- self.store = Redis.new
51
- rescue StandardError => e
52
- e.inspect
53
- e.message
54
- end
55
- def self.set(key, val) self.store.set(key, val) end
56
- def self.get(key) self.store.get(key) end
57
- def self.del(key) self.store.set(key, nil) end
58
- end
59
-
60
- class MemoryCache
61
- class << self
62
- attr_accessor :store
63
- end
64
- def store=(value) self.class.store = value end
65
- def store() self.class.store end
66
- self.store = {}
67
- def self.set(key, val) self.store[key] = val end
68
- def self.get(key) self.store[key] end
69
- def self.del(key) self.store[key] = nil end
46
+ begin
47
+ self.store = Redis.new
48
+ rescue StandardError => e
49
+ e.inspect
50
+ e.message
70
51
  end
52
+ def self.set(key, val) self.store.set(key, val) end
53
+ def self.get(key) self.store.get(key) end
54
+ def self.del(key) self.store.del(key) end
55
+ end
56
+
57
+ class MemoryCache
58
+ class << self; attr_accessor :store; end
59
+ #def store=(value) self.class.store = value end
60
+ #def store() self.class.store end
61
+ self.store = {}
62
+ def self.set(key, val) self.store[key] = val end
63
+ def self.get(key) self.store[key] end
64
+ def self.del(key) self.store[key] = nil end
65
+ end
71
66
 
67
+ class Cache
68
+ CACHE_PREFIX='cache'
69
+ LOG_COMPONENT='Tng::Gtk::Utils::Cache'
72
70
  STRATEGIES = {
73
- redis: RedisCache,
71
+ redis: RedisCache,
74
72
  memory: MemoryCache
75
73
  }
76
- class << self
77
- attr_accessor :strategy
78
- end
74
+ class << self; attr_accessor :strategy; end
75
+
76
+ #def strategy=(value) self.class.strategy = value end
77
+ #def strategy() self.class.strategy end
79
78
 
80
- def strategy=(value) self.class.strategy = value end
81
- def strategy() self.class.strategy end
82
-
83
79
  self.strategy = ENV['REDIS_URL'] ? STRATEGIES[:redis] : STRATEGIES[:memory]
84
- STDERR.puts "Strategy used: #{self.strategy}"
85
-
86
- def self.set(records)
87
- if records.is_a?(Hash)
88
- STDERR.puts "Setting key '#{records[:uuid]}' with value '#{records}' (strategy #{self.strategy})"
89
- self.strategy.set(records[:uuid], records) if records.key?(:uuid)
90
- return
91
- end
92
- records.each do |record|
93
- STDERR.puts "Setting key '#{record[:uuid]}' with value '#{record}' (strategy #{self.strategy})"
94
- self.strategy.set(record[:uuid], record) if record.key?(:uuid)
80
+ Tng::Gtk::Utils::Logger.info(start_stop: 'START', component:'Tng::Gtk::Utils::Cache', operation:'class definition', message:"Strategy used: #{self.strategy}")
81
+
82
+ def self.cache(record)
83
+ unless record.key?(:uuid)
84
+ Tng::Gtk::Utils::Logger.error(component: LOG_COMPONENT, operation:'.cache', message:"Cache key :uuid is missing in record #{record}")
85
+ return nil
95
86
  end
87
+ Tng::Gtk::Utils::Logger.info(component: LOG_COMPONENT, operation:'.cache', message:"Cache key '#{CACHE_PREFIX}:#{record[:uuid]}' with value '#{record}' (strategy #{self.strategy})")
88
+ self.strategy.set("#{CACHE_PREFIX}:#{record[:uuid]}", record.to_json)
89
+ record
90
+ end
91
+ def self.cached?(key)
92
+ Tng::Gtk::Utils::Logger.info(component: LOG_COMPONENT, operation:'.cached?', message:"Cached? key '#{CACHE_PREFIX}:#{key}' (strategy #{self.strategy})")
93
+ data = self.strategy.get("#{CACHE_PREFIX}:#{key}")
94
+ return '' if data.nil?
95
+ JSON.parse(data, symbolize_names: :true)
96
96
  end
97
- def self.get(key)
98
- STDERR.puts "Getting key '#{key}' (strategy #{self.strategy})"
99
- self.strategy.get(key)
97
+ def self.clear(key)
98
+ Tng::Gtk::Utils::Logger.info(component: LOG_COMPONENT, operation:'.clear', message:"Clearing key '#{key}' (strategy #{self.strategy})")
99
+ self.strategy.del(key)
100
100
  end
101
- def self.del(key) self.strategy.del(key) end
101
+ Tng::Gtk::Utils::Logger.info(start_stop: 'STOP', component:'Tng::Gtk::Utils::Cache', operation:'class definition', message:"Strategy used: #{self.strategy}")
102
102
  end
103
103
  end
104
104
  end
@@ -41,12 +41,12 @@ module Tng
41
41
  module Utils
42
42
 
43
43
  class Fetch
44
- class << self
45
- attr_accessor :site
46
- end
44
+ NO_CACHE=ENV.fetch('NO_CACHE', nil)
45
+
46
+ class << self; attr_accessor :site; end
47
47
 
48
- def site=(value) self.class.site = value end
49
- def site() self.class.site end
48
+ #def site=(value) self.class.site = value end
49
+ #def site() self.class.site end
50
50
 
51
51
  def self.call(params)
52
52
  msg=self.name+'#'+__method__.to_s
@@ -54,10 +54,9 @@ module Tng
54
54
  original_params = params.dup
55
55
  begin
56
56
  if params.key?(:uuid)
57
- cached = Tng::Gtk::Utils::Cache.get(params[:uuid])
58
- if cached
59
- STDERR.puts "#{msg}: cached=#{cached}"
60
- return cached
57
+ unless NO_CACHE
58
+ cached = Tng::Gtk::Utils::Cache.cached?(params[:uuid])
59
+ return cached if cached
61
60
  end
62
61
  uuid = params.delete :uuid
63
62
  uri = URI.parse("#{self.site}/#{uuid}")
@@ -76,28 +75,40 @@ module Tng
76
75
  body = response.read_body
77
76
  STDERR.puts "#{msg}: 200 (Ok) body=#{body}"
78
77
  result = JSON.parse(body, quirks_mode: true, symbolize_names: true)
79
- Tng::Gtk::Utils::Cache.set(result)
78
+ cache_result(result)
80
79
  return result
81
80
  when Net::HTTPNotFound
82
- STDERR.puts "#{msg}: 404 Not found) body=#{body}"
81
+ STDERR.puts "#{msg}: 404 Not found body=#{body}"
83
82
  return {} unless uuid.nil?
84
83
  return []
85
84
  else
86
- return nil # ArgumentError.new("#{response.message}")
85
+ STDERR.puts "#{msg}: #{response.message}"
86
+ return nil
87
87
  end
88
88
  rescue Exception => e
89
- STDERR.puts "%s - %s: %s" % [Time.now.utc.to_s, msg, e.message]
89
+ STDERR.puts "E, #{Time.now.utc} #{msg}: #{e.message}"
90
90
  end
91
91
  nil
92
92
  end
93
93
 
94
94
  private
95
- # TODO: Get this out of here!
96
95
  def self.sanitize(params)
97
96
  params[:page_number] ||= ENV.fetch('DEFAULT_PAGE_NUMBER', 0)
98
97
  params[:page_size] ||= ENV.fetch('DEFAULT_PAGE_SIZE', 100)
99
98
  params
100
99
  end
100
+
101
+ def self.cache_result(result)
102
+ msg=self.name+'#'+__method__.to_s
103
+ STDERR.puts "#{msg} result=#{result})"
104
+ if result.is_a?(Hash)
105
+ Tng::Gtk::Utils::Cache.cache(result)
106
+ return
107
+ end
108
+ result.each do |record|
109
+ Tng::Gtk::Utils::Cache.cache(ecord)
110
+ end
111
+ end
101
112
  end
102
113
  end
103
114
  end
@@ -0,0 +1,131 @@
1
+ ## Copyright (c) 2015 SONATA-NFV, 2017 5GTANGO [, ANY ADDITIONAL AFFILIATION]
2
+ ## ALL RIGHTS RESERVED.
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ ## Neither the name of the SONATA-NFV, 5GTANGO [, ANY ADDITIONAL AFFILIATION]
17
+ ## nor the names of its contributors may be used to endorse or promote
18
+ ## products derived from this software without specific prior written
19
+ ## permission.
20
+ ##
21
+ ## This work has been performed in the framework of the SONATA project,
22
+ ## funded by the European Commission under Grant number 671517 through
23
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
24
+ ## acknowledge the contributions of their colleagues of the SONATA
25
+ ## partner consortium (www.sonata-nfv.eu).
26
+ ##
27
+ ## This work has been performed in the framework of the 5GTANGO project,
28
+ ## funded by the European Commission under Grant number 761493 through
29
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
30
+ ## acknowledge the contributions of their colleagues of the 5GTANGO
31
+ ## partner consortium (www.5gtango.eu).
32
+ # encoding: utf-8
33
+ # frozen_string_literal: true
34
+ require 'json'
35
+ require 'logger'
36
+
37
+ module Tng
38
+ module Gtk
39
+ module Utils
40
+ class Logger
41
+ LOGFILE = ENV.fetch('LOGFILE', STDOUT)
42
+ LOGLEVEL = ENV.fetch('LOGLEVEL', 'info')
43
+ #LOGGER_LEVELS = ['debug', 'info', 'warn', 'error', 'fatal', 'unknown'].freeze
44
+ LOGGER_LEVELS = ['D', 'I', 'W', 'E', 'F', 'U'].freeze
45
+
46
+ class << self
47
+ def error(start_stop: '', component:, operation:, message:, status: , time_elapsed:)
48
+ generic(type: 'E', start_stop: start_stop, component:component, operation: operation, message:message, status: status, time_elapsed:time_elapsed)
49
+ end
50
+ def warning(start_stop: '', component:, operation: , message:, status: , time_elapsed:)
51
+ generic(type: 'W', start_stop: start_stop, component:component, operation:operation, message:message, status:status, time_elapsed:time_elapsed)
52
+ end
53
+ def info(start_stop: '', component:, operation: , message:, status: , time_elapsed:)
54
+ generic(type: 'I', start_stop: start_stop, component:component, operation:operation, message:message, status:status, time_elapsed:time_elapsed)
55
+ end
56
+ def fatal(start_stop: '', component:, operation: , message:, status: , time_elapsed:)
57
+ generic(type: 'F', start_stop: start_stop, component:component, operation:operation, message:message, status:status, time_elapsed:time_elapsed)
58
+ end
59
+ def debug(start_stop: '', component:, operation:, message:, status:'', time_elapsed:'')
60
+ generic(type: 'D', start_stop: start_stop, component:component, operation:operation, message:message, status:status, time_elapsed:time_elapsed)
61
+ end
62
+ def unknown(start_stop: '', component:, operation: , message:, status: , time_elapsed:)
63
+ generic(type: 'U', start_stop: start_stop, component: component, operation:operation, message: message, status:status, time_elapsed: time_elapsed)
64
+ end
65
+
66
+ private
67
+ def generic(type:, start_stop:, component:, operation:, message:, status:, time_elapsed:)
68
+ LOGFILE.puts "#{{
69
+ type: type, # mandatory, can be I(nfo), W(arning), D(ebug), E(rror), F(atal) or U(nknown)
70
+ timestamp: Time.now.utc, # mandatory
71
+ start_stop: start_stop, # optional, can be empty, 'START' or 'STOP'
72
+ component: component, # mandatory
73
+ operation: operation, # mandatory
74
+ message: message, # mandatory
75
+ status: status, # optional, makes sense for start_stop='END'
76
+ time_elapsed: time_elapsed # optional, makes sense for start_stop='END'
77
+ }.to_json}" if logger_level(type) < LOGLEVEL
78
+ end
79
+
80
+ def logger_level(level)
81
+ LOGGER_LEVELS.find_index(LOGGER_LEVELS[level])
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ =begin
89
+ LOGLEVEL
90
+ Unknown: a message that should always be logged, whatever the logging level set;
91
+ Fatal: an unhandleable error ocurred;
92
+ Error: a handleable error occurred. The service the component delivers should not be interrupted (i.e., it should be able to recover from the error);
93
+ Warning: a warning message;
94
+ Info: a generic (but useful) information about system operation;
95
+ Debug: a low-level information for developers;
96
+
97
+ {
98
+ "type": "I", # mandatory, can be I(nfo), W(arning), D(ebug), E(rror), F(atal) or U(nknown)
99
+ "timestamp": "2018-10-18 15:49:08 UTC", # mandatory
100
+ "start_stop": "END", # optional, can be empty, 'START' or 'STOP'
101
+ "component": "tng-api-gtw", # mandatory
102
+ "operation": "package upload", # mandatory
103
+ "message": "package uploaded 201", # mandatory
104
+ "status": "201", # optional, makes sense for start_stop='END'
105
+ "time_elapsed": "00:01:20" # optional, makes sense for start_stop='END'
106
+ }
107
+
108
+ LOGGER_LEVELS = ['debug', 'info', 'warn', 'error', 'fatal', 'unknown'].freeze
109
+ FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}
110
+
111
+ def initialize(app, options = {})
112
+ @app = app
113
+ @error_io = options[:logger_io]
114
+ @logger = Logger.new(@error_io)
115
+ @error_io.sync = true
116
+ @logger_level = LOGGER_LEVELS.find_index(options[:logger_level].downcase ||= 'debug')
117
+ end
118
+
119
+
120
+ def call(env)
121
+ msg = self.class.name+'#'+__method__.to_s
122
+ env['5gtango.error']=@error_io
123
+ env['5gtango.logger']=@logger
124
+ @logger.info(msg) {"Called"}
125
+
126
+ status, headers, body = @app.call(env)
127
+ @logger.info(msg) {"Finishing with status #{status}"}
128
+ [status, headers, body]
129
+ end
130
+
131
+ =end
@@ -1,7 +1,7 @@
1
1
  module Tng
2
2
  module Gtk
3
3
  module Utils
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.1"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,61 @@
1
+ ## Copyright (c) 2015 SONATA-NFV, 2017 5GTANGO [, ANY ADDITIONAL AFFILIATION]
2
+ ## ALL RIGHTS RESERVED.
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ ## Neither the name of the SONATA-NFV, 5GTANGO [, ANY ADDITIONAL AFFILIATION]
17
+ ## nor the names of its contributors may be used to endorse or promote
18
+ ## products derived from this software without specific prior written
19
+ ## permission.
20
+ ##
21
+ ## This work has been performed in the framework of the SONATA project,
22
+ ## funded by the European Commission under Grant number 671517 through
23
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
24
+ ## acknowledge the contributions of their colleagues of the SONATA
25
+ ## partner consortium (www.sonata-nfv.eu).
26
+ ##
27
+ ## This work has been performed in the framework of the 5GTANGO project,
28
+ ## funded by the European Commission under Grant number 761493 through
29
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
30
+ ## acknowledge the contributions of their colleagues of the 5GTANGO
31
+ ## partner consortium (www.5gtango.eu).
32
+ # encoding: utf-8
33
+ # frozen_string_literal: true
34
+ require_relative '../../../spec_helper'
35
+ require 'securerandom'
36
+ require 'json'
37
+ require 'tng/gtk/utils/cache'
38
+
39
+ class DummyClass
40
+ end
41
+
42
+ RSpec.describe Tng::Gtk::Utils::Cache do
43
+ context 'with UUID' do
44
+ let(:data) {{uuid: SecureRandom.uuid, whatever: 'else'}}
45
+ it 'should have no cached data for unknown key' do
46
+ STDERR.puts "nil? #{Tng::Gtk::Utils::Cache.cached?(SecureRandom.uuid)}"
47
+ expect(Tng::Gtk::Utils::Cache.cached?(SecureRandom.uuid)).to be_empty
48
+ end
49
+ it 'should cache passed data' do
50
+ Tng::Gtk::Utils::Cache.cache data
51
+ expect(Tng::Gtk::Utils::Cache.cached?(data[:uuid])).to eq(data)
52
+ end
53
+ end
54
+ context 'without UUID' do
55
+ let(:data) {{whatever: 'else'}}
56
+ it 'should not cache passed data' do
57
+ Tng::Gtk::Utils::Cache.cache data
58
+ expect(Tng::Gtk::Utils::Cache.cache(data)).to be_nil
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,47 @@
1
+ ## Copyright (c) 2015 SONATA-NFV, 2017 5GTANGO [, ANY ADDITIONAL AFFILIATION]
2
+ ## ALL RIGHTS RESERVED.
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ ## Neither the name of the SONATA-NFV, 5GTANGO [, ANY ADDITIONAL AFFILIATION]
17
+ ## nor the names of its contributors may be used to endorse or promote
18
+ ## products derived from this software without specific prior written
19
+ ## permission.
20
+ ##
21
+ ## This work has been performed in the framework of the SONATA project,
22
+ ## funded by the European Commission under Grant number 671517 through
23
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
24
+ ## acknowledge the contributions of their colleagues of the SONATA
25
+ ## partner consortium (www.sonata-nfv.eu).
26
+ ##
27
+ ## This work has been performed in the framework of the 5GTANGO project,
28
+ ## funded by the European Commission under Grant number 761493 through
29
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
30
+ ## acknowledge the contributions of their colleagues of the 5GTANGO
31
+ ## partner consortium (www.5gtango.eu).
32
+ # encoding: utf-8
33
+ # frozen_string_literal: true
34
+ require_relative '../../../spec_helper'
35
+ require 'tng/gtk/utils/fetch'
36
+
37
+ RSpec.describe Tng::Gtk::Utils::Fetch do
38
+ context 'with UUID' do
39
+ let(:data) {{uuid: SecureRandom.uuid, whatever: 'else'}}
40
+ it 'should cache passed data' do
41
+ cache
42
+ end
43
+ end
44
+ context 'without UUID' do
45
+ it 'should not cache passed data'
46
+ end
47
+ end
@@ -0,0 +1,41 @@
1
+ ## Copyright (c) 2015 SONATA-NFV, 2017 5GTANGO [, ANY ADDITIONAL AFFILIATION]
2
+ ## ALL RIGHTS RESERVED.
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ ## Neither the name of the SONATA-NFV, 5GTANGO [, ANY ADDITIONAL AFFILIATION]
17
+ ## nor the names of its contributors may be used to endorse or promote
18
+ ## products derived from this software without specific prior written
19
+ ## permission.
20
+ ##
21
+ ## This work has been performed in the framework of the SONATA project,
22
+ ## funded by the European Commission under Grant number 671517 through
23
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
24
+ ## acknowledge the contributions of their colleagues of the SONATA
25
+ ## partner consortium (www.sonata-nfv.eu).
26
+ ##
27
+ ## This work has been performed in the framework of the 5GTANGO project,
28
+ ## funded by the European Commission under Grant number 761493 through
29
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
30
+ ## acknowledge the contributions of their colleagues of the 5GTANGO
31
+ ## partner consortium (www.5gtango.eu).
32
+ # encoding: utf-8
33
+ # frozen_string_literal: true
34
+ require_relative '../../../spec_helper'
35
+ require 'tng/gtk/utils/logget'
36
+
37
+ RSpec.describe Tng::Gtk::Utils::Logger do
38
+ it 'should cache passed data' do
39
+ Tng::Gtk::Utils::Logger.error(start_stop: 'START', component:'Tng::Gtk::Utils::Logger', operation: 'Tests', message:'Just testing', status: '', time_elapsed:'')
40
+ end
41
+ end
@@ -1,9 +1,43 @@
1
+ ## Copyright (c) 2015 SONATA-NFV, 2017 5GTANGO [, ANY ADDITIONAL AFFILIATION]
2
+ ## ALL RIGHTS RESERVED.
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ ## Neither the name of the SONATA-NFV, 5GTANGO [, ANY ADDITIONAL AFFILIATION]
17
+ ## nor the names of its contributors may be used to endorse or promote
18
+ ## products derived from this software without specific prior written
19
+ ## permission.
20
+ ##
21
+ ## This work has been performed in the framework of the SONATA project,
22
+ ## funded by the European Commission under Grant number 671517 through
23
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
24
+ ## acknowledge the contributions of their colleagues of the SONATA
25
+ ## partner consortium (www.sonata-nfv.eu).
26
+ ##
27
+ ## This work has been performed in the framework of the 5GTANGO project,
28
+ ## funded by the European Commission under Grant number 761493 through
29
+ ## the Horizon 2020 and 5G-PPP programmes. The authors would like to
30
+ ## acknowledge the contributions of their colleagues of the 5GTANGO
31
+ ## partner consortium (www.5gtango.eu).
32
+ # encoding: utf-8
33
+ # frozen_string_literal: true
34
+ require_relative '../../spec_helper'
35
+ require 'securerandom'
36
+ require 'json'
37
+ require 'tng/gtk/utils'
38
+
1
39
  RSpec.describe Tng::Gtk::Utils do
2
40
  it "has a version number" do
3
41
  expect(Tng::Gtk::Utils::VERSION).not_to be nil
4
42
  end
5
-
6
- it "does something useful" do
7
- expect(false).to eq(true)
8
- end
9
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tng-gtk-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Bonnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,8 +105,12 @@ files:
105
105
  - lib/tng/gtk/utils.rb
106
106
  - lib/tng/gtk/utils/cache.rb
107
107
  - lib/tng/gtk/utils/fetch.rb
108
+ - lib/tng/gtk/utils/logger.rb
108
109
  - lib/tng/gtk/utils/version.rb
109
110
  - spec/spec_helper.rb
111
+ - spec/tng/gtk/utils/cache_spec.rb
112
+ - spec/tng/gtk/utils/fetch_spec.rb
113
+ - spec/tng/gtk/utils/logger_spec.rb
110
114
  - spec/tng/gtk/utils_spec.rb
111
115
  - tng-gtk-utils.gemspec
112
116
  homepage: https://github.com/sonata-nfv/tng-gtk-utils
@@ -135,4 +139,7 @@ specification_version: 4
135
139
  summary: A small library with utility features for 5GTANGO Gatekeeper
136
140
  test_files:
137
141
  - spec/spec_helper.rb
142
+ - spec/tng/gtk/utils/cache_spec.rb
143
+ - spec/tng/gtk/utils/fetch_spec.rb
144
+ - spec/tng/gtk/utils/logger_spec.rb
138
145
  - spec/tng/gtk/utils_spec.rb