From 410fee4f8dd8fe5d850ff1be8404046d902aad40 Mon Sep 17 00:00:00 2001 From: Romain Georges Date: Tue, 16 Apr 2024 19:21:19 +0200 Subject: [PATCH] adding tests and minors updates --- .rubocop.yml | 6 +- bom.xml | 264 +++++++++++++-------------------- carioca.gemspec | 2 + lib/carioca/constants.rb | 2 +- lib/carioca/services/debug.rb | 6 +- lib/carioca/services/output.rb | 8 +- samples/config/settings.yml | 2 +- samples/test.rb | 4 +- spec/carioca_spec.rb | 170 +++++++++++++++++++++ spec/config/carioca.registry | 7 + spec/config/locales/en.yml | 3 + spec/config/locales/es.yml | 2 + spec/config/locales/fr.yml | 2 + spec/config/settings.yml | 47 ++++++ spec/sample_service.rb | 22 +++ spec/spec_helper.rb | 1 + spec/test_container.rb | 20 +++ 17 files changed, 398 insertions(+), 170 deletions(-) create mode 100644 spec/config/carioca.registry create mode 100644 spec/config/locales/en.yml create mode 100644 spec/config/locales/es.yml create mode 100644 spec/config/locales/fr.yml create mode 100644 spec/config/settings.yml create mode 100644 spec/sample_service.rb create mode 100644 spec/test_container.rb diff --git a/.rubocop.yml b/.rubocop.yml index 7f6c337..248fb5f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -49,4 +49,8 @@ Layout/LineLength: Enabled: false Metrics/ParameterLists: - Max: 8 \ No newline at end of file + Max: 8 + +Gemspec/DevelopmentDependencies: + Exclude: + - 'carioca.gemspec' \ No newline at end of file diff --git a/bom.xml b/bom.xml index da763c5..14a34d2 100644 --- a/bom.xml +++ b/bom.xml @@ -1,5 +1,5 @@ - + ast @@ -45,17 +45,17 @@ carioca - 2.1.0 + 2.1.5 Carioca : Container And Registry with Inversion Of Control for your Applications - 4e89e5c23f92aa4731ca58110218d9b9b82ff5075a5bf500a96e19ba1ca9d1e1 + 100d0fae4d1a8449e10c055bc5923bf710abb7c4d7c327b02c5cd4639e4984e5 BSD-3-Clause - pkg:gem/carioca@2.1.0 + pkg:gem/carioca@2.1.5 code_statistics @@ -68,17 +68,17 @@ concurrent-ruby - 1.2.2 + 1.2.3 Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell, F#, C#, Java, and classic concurrency patterns. - 3879119b8b75e3b62616acc256c64a134d0b0a7a9a3fcba5a233025bcde22c4f + 82fdd3f8a0816e28d513e637bb2b90a45d7b982bdf4f3a0511722d2e495801e2 MIT - pkg:gem/concurrent-ruby@1.2.2 + pkg:gem/concurrent-ruby@1.2.3 cyclonedx-ruby @@ -110,31 +110,31 @@ diff-lcs - 1.5.0 + 1.5.1 Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm - 49b934001c8c6aedb37ba19daec5c634da27b318a7a3c654ae979d6ba1929b67 + 273223dfb40685548436d32b4733aa67351769c7dea621da7d9dd4813e63ddfe MIT - pkg:gem/diff-lcs@1.5.0 + pkg:gem/diff-lcs@1.5.1 domain_name - 0.5.20190701 + 0.6.20240107 Domain Name manipulation library for Ruby - 000a600454cb4a344769b2f10b531765ea7bd3a304fe47ed12e5ca1eab969851 + 5f693b2215708476517479bf2b3802e49068ad82167bcd2286f899536a17d933 BSD-2-Clause - pkg:gem/domain_name@0.5.20190701 + pkg:gem/domain_name@0.6.20240107 http-accept @@ -161,87 +161,87 @@ i18n - 1.14.1 + 1.14.4 New wave Internationalization support for Ruby - 9d03698903547c060928e70a9bc8b6b87fda674453cda918fc7ab80235ae4a61 + c7deedead0866ea9102975a4eab7968f53de50793a0c211a37808f75dd187551 MIT - pkg:gem/i18n@1.14.1 + pkg:gem/i18n@1.14.4 json - 2.6.2 + 2.7.2 JSON Implementation for Ruby - cc9eedb357374667fe2b45e2a7fa65af517cc33bbfa12f56a14953f38a4845f5 + 138e3038b5361b3d06ee2e8aa2be00bed0d0de4ef5f1553fc5935e5b93aca7ee Ruby - pkg:gem/json@2.6.2 + pkg:gem/json@2.7.2 - locale - 2.1.3 - Ruby-Locale is the pure ruby library which provides basic APIs for localization. + language_server-protocol + 3.17.0.3 + A Language Server Protocol SDK - b6ddee011e157817cb98e521b3ce7cb626424d5882f1e844aafdee3e8b212725 + 3d5c58c02f44a20d972957a9febe386d7e7468ab3900ce6bd2b563dd910c6b3f - Ruby + MIT - pkg:gem/locale@2.1.3 + pkg:gem/language_server-protocol@3.17.0.3 - mime-types - 3.4.1 - The mime-types library provides a library and registry for information about MIME content type definitions + locale + 2.1.4 + Ruby-Locale is the pure ruby library which provides basic APIs for localization. - 6bcf8b0e656b6ae9977bdc1351ef211d0383252d2f759a59ef4bcf254542fc46 + 522f9973ef3eee64aac9bca06d21db2fba675fa3d2cf61d21f42d1ca18a9f780 - MIT + Ruby - pkg:gem/mime-types@3.4.1 + pkg:gem/locale@2.1.4 - mime-types-data - 3.2023.0218.1 - mime-types-data provides a registry for information about MIME media type definitions + mime-types + 3.5.2 + The mime-types library provides a library and registry for information about MIME content type definitions - e90f027e54346bbbf7bd993a97e9cb7270cd4fe41c535ef84bf5d1aefe1e7ede + c1299f10fa34c75a6f168e99e9dadbd11bc507d9d62dc5cf98c4e65f2af8c4e4 MIT - pkg:gem/mime-types-data@3.2023.0218.1 + pkg:gem/mime-types@3.5.2 - mini_portile2 - 2.8.2 - Simplistic port-like solution for developers + mime-types-data + 3.2024.0305 + mime-types-data provides a registry for information about MIME media type definitions - 46b2d244cc6ff01a89bf61274690c09fdbdca47a84ae9eac39039e81231aee7c + a5101ed02bf708fbaf1f65453d9dd27ece1bf910bece3df61835498d7be1a703 MIT - pkg:gem/mini_portile2@2.8.2 + pkg:gem/mime-types-data@3.2024.0305 netrc @@ -259,31 +259,17 @@ nokogiri - 1.15.2 + 1.16.4 Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby. - 20dc800b8fbe4c4f4b5b164e6aa3ab82a371bcb27eb685c166961c34dd8a22d7 + 62c116c3a14b4ed4e1faec786da266c4bd4c717a0bd04a9916164a7046040f45 MIT - pkg:gem/nokogiri@1.15.2 - - - nokogiri - 1.15.2 - Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby. - - 20dc800b8fbe4c4f4b5b164e6aa3ab82a371bcb27eb685c166961c34dd8a22d7 - - - - MIT - - - pkg:gem/nokogiri@1.15.2 + pkg:gem/nokogiri@1.16.4 ostruct @@ -301,31 +287,31 @@ parallel - 1.22.1 + 1.24.0 Run any kind of code in parallel processes - ebdf1f0c51f182df38522f70ba770214940bef998cdb6e00f36492b29699761f + 5bf38efb9b37865f8e93d7a762727f8c5fc5deb19949f4040c76481d5eee9397 MIT - pkg:gem/parallel@1.22.1 + pkg:gem/parallel@1.24.0 parser - 3.1.2.0 + 3.3.0.5 A Ruby parser written in pure Ruby. - eda4d7b49bbfddad3b6ca9cdfb23302eec6cf73c2e808b6d5b0cc9161f7c0e76 + 7748313e505ca87045dc0465c776c802043f777581796eb79b1654c5d19d2687 MIT - pkg:gem/parser@3.1.2.0 + pkg:gem/parser@3.3.0.5 pastel @@ -357,17 +343,17 @@ racc - 1.7.1 + 1.7.3 Racc is a LALR(1) parser generator - eaa5cd10ace36a5c5a139e699875a45fa1dfd7d5df8432ffd6243962c6b24ef0 + b2ad737e788cfa083263ce7c9290644bb0f2c691908249eb4f6eb48ed2815dbf Ruby - pkg:gem/racc@1.7.1 + pkg:gem/racc@1.7.3 rainbow @@ -385,31 +371,31 @@ rake - 13.0.6 + 13.2.1 Rake is a Make-like program implemented in Ruby - 5ce4bf5037b4196c24ac62834d8db1ce175470391026bd9e557d669beeb19097 + 46cb38dae65d7d74b6020a4ac9d48afed8eb8149c040eccf0523bec91907059d MIT - pkg:gem/rake@13.0.6 + pkg:gem/rake@13.2.1 regexp_parser - 2.5.0 + 2.9.0 Scanner, lexer, parser for ruby's regular expressions - a076d2d35ab8d11feab5fecf8aa09ec6df68c2429810748cba079f7b021ecde5 + 81a00ba141cec0d4b4bf58cb80cd9193e5180836d3fa6ef623f7886d3ba8bdd9 MIT - pkg:gem/regexp_parser@2.5.0 + pkg:gem/regexp_parser@2.9.0 rest-client @@ -427,143 +413,143 @@ rexml - 3.2.5 + 3.2.6 An XML toolkit for Ruby - a33c3bf95fda7983ec7f05054f3a985af41dbc25a0339843bd2479e93cabb123 + e0669a2d4e9f109951cb1fde723d8acd285425d81594a2ea929304af50282816 BSD-2-Clause - pkg:gem/rexml@3.2.5 + pkg:gem/rexml@3.2.6 rspec - 3.9.0 - rspec-3.9.0 + 3.13.0 + rspec-3.13.0 - 90a037a7cc02365d7c112201881839aafbc875a88094423bc8cba778c98bfac3 + d490914ac1d5a5a64a0e1400c1d54ddd2a501324d703b8cfe83f458337bab993 MIT - pkg:gem/rspec@3.9.0 + pkg:gem/rspec@3.13.0 rspec-core - 3.9.3 - rspec-core-3.9.3 + 3.13.0 + rspec-core-3.13.0 - 704f3af166bb8d763199742d94f0be3027c0f26d61a2f2156d99d0444248082d + 557792b4e88da883d580342b263d9652b6a10a12d5bda9ef967b01a48f15454c MIT - pkg:gem/rspec-core@3.9.3 + pkg:gem/rspec-core@3.13.0 rspec-expectations - 3.9.4 - rspec-expectations-3.9.4 + 3.13.0 + rspec-expectations-3.13.0 - 58248bcc7ca1cde7255aa2436d27a1a6133d8d235409011b5256a24ce050583e + 621d48c62262f955421eaa418130744760802cad47e781df70dba4d9f897102e MIT - pkg:gem/rspec-expectations@3.9.4 + pkg:gem/rspec-expectations@3.13.0 rspec-mocks - 3.9.1 - rspec-mocks-3.9.1 + 3.13.0 + rspec-mocks-3.13.0 - b9820ed35afbc552b4448ccb98984ffe20e92bff6760dbd60f4fec503d6e75a7 + 735a891215758d77cdb5f4721fffc21078793959d1f0ee4a961874311d9b7f66 MIT - pkg:gem/rspec-mocks@3.9.1 + pkg:gem/rspec-mocks@3.13.0 rspec-support - 3.9.4 - rspec-support-3.9.4 + 3.13.1 + rspec-support-3.13.1 - f4333c6df9413909aa652e8460588b36e8bb62e76e51e94c039e1b4bc3e4e645 + 48877d4f15b772b7538f3693c22225f2eda490ba65a0515c4e7cf6f2f17de70f MIT - pkg:gem/rspec-support@3.9.4 + pkg:gem/rspec-support@3.13.1 rubocop - 1.32.0 + 1.63.1 Automatic Ruby code style checking tool. - 82d2a9c2995324ee0d27b75f4396d30a021e965c0e82c39162e7041a6a386326 + 63b3708babf7ede96e17c8ec03a96fc3c162a1c267579d7c9e477d25650d1b73 MIT - pkg:gem/rubocop@1.32.0 + pkg:gem/rubocop@1.63.1 rubocop-ast - 1.19.1 + 1.31.2 RuboCop tools to deal with Ruby code AST. - f549a8f636a3d4d7bc235ee091a7cea955441cf7a250d124d44e218df91b1841 + 7c206fb094553779923eca862aceece3913ce384f1bf85730208228e884578ec MIT - pkg:gem/rubocop-ast@1.19.1 + pkg:gem/rubocop-ast@1.31.2 ruby-progressbar - 1.11.0 + 1.13.0 Ruby/ProgressBar is a flexible text progress bar library for Ruby. - cc127db3866dc414ffccbf92928a241e585b3aa2b758a5563e74a6ee0f57d50a + 80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33 MIT - pkg:gem/ruby-progressbar@1.11.0 + pkg:gem/ruby-progressbar@1.13.0 thor - 1.2.2 + 1.3.1 Thor is a toolkit for building powerful command-line interfaces. - 2f93c652828cba9fcf4f65f5dc8c306f1a7317e05aad5835a13740122c17f24c + fa7e3471d4f6a27138e3d9c9b0d4daac9c3d7383927667ae83e9ab42ae7401ef MIT - pkg:gem/thor@1.2.2 + pkg:gem/thor@1.3.1 tty-color @@ -623,59 +609,31 @@ tty-screen - 0.8.1 - Terminal screen size detection which works on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby, TruffleRuby and Rubinius interpreters. + 0.8.2 + Terminal screen size detection. - 6508657c38f32bdca64880abe201ce237d80c94146e1f9b911cba3c7823659a2 + c090652115beae764336c28802d633f204fb84da93c6a968aa5d8e319e819b50 MIT - pkg:gem/tty-screen@0.8.1 - - - unf - 0.1.4 - A wrapper library to bring Unicode Normalization Form support to Ruby/JRuby - - 49a5972ec0b3d091d3b0b2e00113f2f342b9b212f0db855eb30a629637f6d302 - - - - 2-clause BSDL - - - pkg:gem/unf@0.1.4 - - - unf_ext - 0.0.8.2 - Unicode Normalization Form support library for CRuby - - 6d44c13c98924bebd15ebdd4ed196ead403a0770ac03304570873349fda2a208 - - - - MIT - - - pkg:gem/unf_ext@0.0.8.2 + pkg:gem/tty-screen@0.8.2 unicode-display_width - 2.2.0 + 2.5.0 Determines the monospace display width of a string in Ruby. - 967fa4071b42b2c4afab8375c4f464392c5fb956959c0ceeb3cea0f4cd648eda + 7e7681dcade1add70cb9fda20dd77f300b8587c81ebbd165d14fd93144ff0ab4 MIT - pkg:gem/unicode-display_width@2.2.0 + pkg:gem/unicode-display_width@2.5.0 version @@ -691,20 +649,6 @@ pkg:gem/version@1.1.1 - - webrick - 1.7.0 - HTTP server toolkit - - 87e9b8e39947b7925338a5eb55427b11ce1f2b25a3645770ec9f39d8ebdb8cb4 - - - - Ruby - - - pkg:gem/webrick@1.7.0 - wisper 2.0.1 @@ -721,17 +665,17 @@ yard - 0.9.28 + 0.9.36 Documentation tool for consistent and usable documentation in Ruby. - d31b7e3172405165212e0c8db5b3b57865f0831f1bc33bdda5d0709e1e72315c + 5505736c1b00c926f71053a606ab75f02070c5960d0778b901fe9d8b0a470be4 MIT - pkg:gem/yard@0.9.28 + pkg:gem/yard@0.9.36 yard-rspec diff --git a/carioca.gemspec b/carioca.gemspec index a86038c..5387de9 100644 --- a/carioca.gemspec +++ b/carioca.gemspec @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'diff/lcs' require_relative 'lib/carioca/constants' Gem::Specification.new do |spec| @@ -42,6 +43,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rubocop', '~> 1.32' spec.add_development_dependency 'yard', '~> 0.9.27' spec.add_development_dependency 'yard-rspec', '~> 0.1' + spec.add_development_dependency 'diff-lcs', '~> 1.5.1' spec.metadata['rubygems_mfa_required'] = 'false' spec.add_dependency 'version', '~> 1.1' spec.add_runtime_dependency 'ps-ruby', '~> 0.0.4' diff --git a/lib/carioca/constants.rb b/lib/carioca/constants.rb index 8cbd40e..838afe2 100644 --- a/lib/carioca/constants.rb +++ b/lib/carioca/constants.rb @@ -8,7 +8,7 @@ module Constants DEFAULT_CONFIG_ROOT = :carioca DEFAULT_LOCALE = :en - DEFAULT_OUTPUT_TARGET = $stdout + DEFAULT_OUTPUT_TARGET = :stdout DEFAULT_OUTPUT_MODE = :mono DEFAULT_EMOJI_STATUS = true DEFAULT_COLORS_STATUS = true diff --git a/lib/carioca/services/debug.rb b/lib/carioca/services/debug.rb index 8dd3b89..9c4259b 100644 --- a/lib/carioca/services/debug.rb +++ b/lib/carioca/services/debug.rb @@ -20,8 +20,8 @@ def initialize(service:, trace:) end def method_missing(methodname, *args, **keywords, &) - trace message: "BEGIN CALL for service #{@service} " - trace message: "Method called: #{methodname} " + trace message: "BEGIN CALL for service #{@service.class}" + trace message: "Method called: #{methodname}" trace message: "args : #{args.join ' '}" trace message: "keywords : #{keywords}" if block_given? @@ -30,7 +30,7 @@ def method_missing(methodname, *args, **keywords, &) else a = @service.send(methodname, *args, **keywords) end - trace message: "=> method returned: #{a} " + trace message: "=> method returned: #{a}" trace message: 'END CALL' a diff --git a/lib/carioca/services/output.rb b/lib/carioca/services/output.rb index 6f5c8ec..d94bf27 100644 --- a/lib/carioca/services/output.rb +++ b/lib/carioca/services/output.rb @@ -109,7 +109,7 @@ def add_alias(newalias:, level:) end # constructor - def initialize(level: :debug, mode: :mono, emoji: true, colors: true, target: $stdout) + def initialize(level: :debug, mode: :mono, emoji: true, colors: true, target: :stdout) registry = Carioca::Registry.get @logger = registry.get_service name: :logger @i18n = registry.get_service name: :i18n @@ -183,7 +183,11 @@ def display(level:, message:, session:, source:) block = proc { save } @logger.send target_level, source, &block end - @target.puts message if (@mode == :mono) || (@mode == :dual) + if @target == :stderr then + $stderr.puts message if (@mode == :mono) || (@mode == :dual) + else + $stdout.puts message if (@mode == :mono) || (@mode == :dual) + end end end end diff --git a/samples/config/settings.yml b/samples/config/settings.yml index 596bafa..08423e2 100644 --- a/samples/config/settings.yml +++ b/samples/config/settings.yml @@ -39,7 +39,7 @@ :rules: - :test: :verify_file :name: "/tmp/carioca.registry" - :mode: "644" + :mode: "755" - :test: :verify_folder :name: "/tmp/toto" :mode: "755" diff --git a/samples/test.rb b/samples/test.rb index 6acc0af..0186130 100644 --- a/samples/test.rb +++ b/samples/test.rb @@ -137,10 +137,10 @@ def test3 toolbox = Carioca::Registry.get.get_service name: :toolbox pp toolbox.describe -puts "\nTest 10 : Service toolbox test of simple methode : :user_root" +puts "\nTest 10 : Service toolbox test of simple method : :user_root" pp toolbox.user_root -puts "\nTest 11 : Service toolbox test of simple methode : :search_file_in_gem" +puts "\nTest 11 : Service toolbox test of simple method : :search_file_in_gem" pp toolbox.search_file_in_gem(gem: 'carioca', file: 'config/locales/en.yml') puts "\nTest 12 : Service setup execute setup schema from configuration" diff --git a/spec/carioca_spec.rb b/spec/carioca_spec.rb index 7f17ec5..46d17fb 100644 --- a/spec/carioca_spec.rb +++ b/spec/carioca_spec.rb @@ -1,7 +1,177 @@ # frozen_string_literal: true +require 'bundler/inline' + +gemfile do + source 'https://rubygems.org' + gem 'uuid' + gem 'carioca' +end + RSpec.describe Carioca do + + before :all do + # Configuration of Carioca + + + + Carioca::Registry.configure do |spec| + spec.filename = './spec/config/carioca.registry' + spec.debug = false + spec.init_from_file = true + spec.log_file = '/tmp/test.rge' + spec.config_file = './spec/config/settings.yml' + spec.config_root = :myappli + spec.environment = :development + spec.default_locale = :fr + spec.log_level = :debug + spec.output_mode = :dual + spec.output_emoji = true + spec.output_colors = true + spec.locales_load_path << Dir["#{File.expand_path('./spec/config/locales')}/*.yml"] + spec.debugger_tracer = :output + end + + require_relative 'sample_service' + require_relative 'test_container' + + + end + it 'has a version number' do expect(Carioca::VERSION).not_to be nil end + + context "Testing own Service, Logger & Output Service" do + + it "must access to registry : adding a internal service MyService" do + + spec = { + service: 'MyService::new', + type: :internal + } + Carioca::Registry.init.add service: :myservice, definition: spec + end + + it "must be possible to list of avaible services : MyService include" do + logger = Carioca::Registry.get.get_service name: :logger + logger.info(to_s) { "Available services : #{Carioca::Registry.get.services.keys} " } + end + + + it "must be possible to use output service" do + output = Carioca::Registry.get.get_service name: :output + expect { output.info "test" }.to output("ℹ \e[36mtest\e[0m\n").to_stdout + end + + it "must be possible to use MyService" do + myservice = Carioca::Registry.get.get_service name: :myservice + expect { myservice.hello }.to output("ℹ \e[36mHello World\e[0m\n").to_stdout + + end + end + + context "I18n Service" do + + it "must be possible to use the I18n service with locales :es, :fr, :en via output service" do + + i18n = Carioca::Registry.get.get_service name: :i18n + output = Carioca::Registry.get.get_service name: :output + {es: "español", fr: "français", en: "english"}.each do |locale,result| + i18n.locale = locale + expect { output.item i18n.t(:test) }.to output(" 🔹 \e[37m#{result}\e[0m\n").to_stdout + end + end + + + it "must be possible to use the I18n service and test fallback :en on local :es for missing :es locale" do + i18n = Carioca::Registry.get.get_service name: :i18n + output = Carioca::Registry.get.get_service name: :output + i18n.locale = :es + expect { output.item i18n.t(:fallback) }.to output(" 🔹 \e[37menglish fallback\e[0m\n").to_stdout + i18n.locale = :en + end + end + + context "Configuration Service" do + it "must be possible to use Configuration service retrieving all merged data for :development environnement " do + result_tree = {:default_value=>"value", + :treeA=>{:trunk1=>{:branch2=>"leaf2", :branch1=>"leaf1"}, :trunk2=>{:branch5=>["value", "val1", "val2", "val3"], :branch3=>"leaf3", :branch4=>"leaf4"}}, + :setup=> + {:rules=> + [{:action=>:install_file, :source=>"samples/config/settings.yml", :target=>"/tmp/settings.yml"}, + {:action=>:install_file, :source=>"samples/config/carioca.registry", :target=>"/tmp/carioca.registry", :mode=>"755"}, + {:action=>:make_folder, :path=>"/tmp/toto", :mode=>"755"}, + {:action=>:make_link, :source=>"/tmp/settings.yml", :link=>"/tmp/application.yml"}]}, + :sanitycheck=>{:rules=>[{:test=>:verify_file, :name=>"/tmp/carioca.registry", :mode=>"755"}, {:test=>:verify_folder, :name=>"/tmp/toto", :mode=>"755"}, {:test=>:verify_link, :name=>"/tmp/application.yml"}]}, + :ondev=>"test"} + config = Carioca::Registry.get.get_service name: :configuration + expect(config.settings.to_h).to eq result_tree + end + + it "must be possible to add new data on runtime" do + config = Carioca::Registry.get.get_service name: :configuration + config.settings.newkey = 'value' + expect(config.settings.newkey).to eq 'value' + end + + it "must be possible to override data on runtime" do + config = Carioca::Registry.get.get_service name: :configuration + config.settings.trunk1.branch2 = 'newleaf' + expect(config.settings.trunk1.branch2).to eq 'newleaf' + end + + end + + context "Container test (Output, Self service, Debugger and registry config service type :gem)" do + + it "must be possible to use Carioca Container with Config file defined gem service in registry UUID (logging) see : /tmp/test.rge" do + appli = MyAppli.new + expect { appli.test }.to output("ℹ \e[36mHello World\e[0m\n").to_stdout + end + + + it "must be possible to use Carioca Container with debbugger service for own service" do + appli = MyAppli.new + expect { appli.test2 }.to output("🐛 \e[35mBEGIN CALL for service MyService\e[0m\n🐛 \e[35mMethod called: method_test\e[0m\n🐛 \e[35margs : param\e[0m\n🐛 \e[35mkeywords : {:tutu=>\"keyword\"}\e[0m\n🐛 \e[35mblock given\e[0m\ntiti\n🐛 \e[35m=> method returned: result keyword\e[0m\n🐛 \e[35mEND CALL\e[0m\n").to_stdout + end + + end + + context "Service Toolbox" do + it "muts be possible to get the Service Toolbox list of availables methodes" do + toolbox = Carioca::Registry.get.get_service name: :toolbox + expect(toolbox.describe).to eq({ + :get_processes => "Get the list of running processus", + :root? => "Verify if active current processus is running as root", + :check_unicode_term => "Check if terminal support unicode", + :user_root => "Get the local system root username ", + :group_root => "Get the local system root groupname ", + :search_file_in_gem => "Retrieve absolute path of a file in a specific gem"}) + end + + it "must be possible to use one of the method from Service toolbox : :user_root" do + toolbox = Carioca::Registry.get.get_service name: :toolbox + expect(toolbox.user_root).to eq "root" + end + + it "must be possible to use one of the method from Service toolbox : :search_file_in_gem" do + toolbox = Carioca::Registry.get.get_service name: :toolbox + expect(Pathname.new(toolbox.search_file_in_gem(gem: 'carioca', file: 'config/locales/en.yml'))).to exist + end + + end + + context "Setup and Sanitycheck Service" do + it "must be possible on Service setup to execute setup schema from configuration" do + setup = Carioca::Registry.get.get_service name: :setup + expect { setup.execute! }.to output("ℹ \e[36mBegining setup :\e[0m\n 🔹 \e[37mInstallation of file /tmp/settings.yml\e[0m\n 🔹 \e[37mInstallation of file /tmp/carioca.registry\e[0m\n 🔹 \e[37mCreation of folder /tmp/toto\e[0m\n 🔹 \e[37mCreation of symlink /tmp/application.yml -> /tmp/settings.yml\e[0m\n").to_stdout + end + it "must be possible on Service sanitycheck to run checking schema from configuration" do + sanitycheck = Carioca::Registry.get.get_service name: :sanitycheck + expect { sanitycheck.run }.to output("ℹ \e[36mBegining sanitycheck :\e[0m\n👍 \e[32mTestcase verify_file on /tmp/carioca.registry is ok\e[0m\n👍 \e[32mTestcase verify_folder on /tmp/toto is ok\e[0m\n👍 \e[32mTestcase verify_link on /tmp/application.yml is ok\e[0m\n💪 \e[32mSanitycheck finish without errors\e[0m\n").to_stdout + end + end + + end diff --git a/spec/config/carioca.registry b/spec/config/carioca.registry new file mode 100644 index 0000000..b920cd7 --- /dev/null +++ b/spec/config/carioca.registry @@ -0,0 +1,7 @@ +--- +:uuid: + :type: :gem + :description: The uuid service + :service: UUID + :resource: uuid + diff --git a/spec/config/locales/en.yml b/spec/config/locales/en.yml new file mode 100644 index 0000000..8ca13de --- /dev/null +++ b/spec/config/locales/en.yml @@ -0,0 +1,3 @@ +en: + test: 'english' + fallback: "english fallback" \ No newline at end of file diff --git a/spec/config/locales/es.yml b/spec/config/locales/es.yml new file mode 100644 index 0000000..deea55c --- /dev/null +++ b/spec/config/locales/es.yml @@ -0,0 +1,2 @@ +es: + test: 'español' \ No newline at end of file diff --git a/spec/config/locales/fr.yml b/spec/config/locales/fr.yml new file mode 100644 index 0000000..6a41847 --- /dev/null +++ b/spec/config/locales/fr.yml @@ -0,0 +1,2 @@ +fr: + test: 'français' \ No newline at end of file diff --git a/spec/config/settings.yml b/spec/config/settings.yml new file mode 100644 index 0000000..08423e2 --- /dev/null +++ b/spec/config/settings.yml @@ -0,0 +1,47 @@ +--- +:myappli: + :production: {} + :staging: + :onstaging: staging + :test: {} + :development: + :ondev: test + :treeA: + :trunk1: + :branch1: leaf1 + :trunk2: + :branch3: leaf3 + :branch4: leaf4 + :branch5: [ "val1","val2","val3" ] + :default: + :default_value: 'value' + :treeA: + :trunk1: + :branch2: leaf2 + :trunk2: + :branch5: ["value"] + :setup: + :rules: + - :action: :install_file + :source: "samples/config/settings.yml" + :target: "/tmp/settings.yml" + - :action: :install_file + :source: "samples/config/carioca.registry" + :target: "/tmp/carioca.registry" + :mode: "755" + - :action: :make_folder + :path: /tmp/toto + :mode: "755" + - :action: :make_link + :source: /tmp/settings.yml + :link: /tmp/application.yml + :sanitycheck: + :rules: + - :test: :verify_file + :name: "/tmp/carioca.registry" + :mode: "755" + - :test: :verify_folder + :name: "/tmp/toto" + :mode: "755" + - :test: :verify_link + :name: "/tmp/application.yml" diff --git a/spec/sample_service.rb b/spec/sample_service.rb new file mode 100644 index 0000000..2a78a6b --- /dev/null +++ b/spec/sample_service.rb @@ -0,0 +1,22 @@ +# test fo internal specific service +class MyService + extend Carioca::Injector + inject service: :logger + inject service: :output + + def initialize + logger.warn(self.class.to_s) { 'Init service' } + end + + def hello + output.info 'Hello World' + end + + def method_test(_titi, tutu:) + @tutu = tutu + yield if block_given? + "result #{@tutu}" + end + end + + \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d9b6963..42a2625 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'carioca' +require 'pathname' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure diff --git a/spec/test_container.rb b/spec/test_container.rb new file mode 100644 index 0000000..c94246e --- /dev/null +++ b/spec/test_container.rb @@ -0,0 +1,20 @@ +class MyAppli < Carioca::Container + def test + myservice.hello + logger.warn(self.class.to_s) { uuid.generate } + end + + inject service: :uuid + inject service: :myservice + logger.info(to_s) { uuid.generate } + + inject service: :output + inject service: :debugger + + def test2 + proxy = debugger.get service: :myservice + proxy.method_test 'param', tutu: 'keyword' do + puts 'titi' + end + end + end \ No newline at end of file