From 5b8c4bc1bd9b0ced124b7757aef7bbb04238ee60 Mon Sep 17 00:00:00 2001 From: Denys Medynskyi Date: Wed, 3 Jun 2020 18:43:04 +0300 Subject: [PATCH] Add Namespace Validator object --- .rspec | 2 ++ Gemfile.lock | 2 +- lib/kube-dsl.rb | 1 + lib/kube-dsl/dsl_object.rb | 1 + lib/kube-dsl/validator.rb | 9 +++++++++ lib/spec/kube-dsl/dsl/v1/namespace_spec.rb | 19 +++++++++++++++++++ lib/spec/spec_helper.rb | 8 ++++++++ 7 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .rspec create mode 100644 lib/kube-dsl/validator.rb create mode 100644 lib/spec/kube-dsl/dsl/v1/namespace_spec.rb create mode 100644 lib/spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..16f9cdb0 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/Gemfile.lock b/Gemfile.lock index 95f5717c..19c84f17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - kube-dsl (0.1.0) + kube-dsl (0.2.0) dry-inflector (~> 0.2) GEM diff --git a/lib/kube-dsl.rb b/lib/kube-dsl.rb index 77f214d9..d22329ce 100644 --- a/lib/kube-dsl.rb +++ b/lib/kube-dsl.rb @@ -15,6 +15,7 @@ module KubeDSL autoload :ResourceMeta, 'kube-dsl/resource_meta' autoload :StringHelpers, 'kube-dsl/string_helpers' autoload :ValueFields, 'kube-dsl/value_fields' + autoload :Validator, 'kube-dsl/validator' extend Entrypoint end diff --git a/lib/kube-dsl/dsl_object.rb b/lib/kube-dsl/dsl_object.rb index 99af1432..7875b6e3 100644 --- a/lib/kube-dsl/dsl_object.rb +++ b/lib/kube-dsl/dsl_object.rb @@ -1,6 +1,7 @@ module KubeDSL class DSLObject extend ::KubeDSL::ValueFields + include ::KubeDSL::Validator def initialize(&block) instance_eval(&block) if block diff --git a/lib/kube-dsl/validator.rb b/lib/kube-dsl/validator.rb new file mode 100644 index 00000000..083fc156 --- /dev/null +++ b/lib/kube-dsl/validator.rb @@ -0,0 +1,9 @@ +require 'pry' + +module KubeDSL + module Validator + def validate! + binding.pry + end + end +end diff --git a/lib/spec/kube-dsl/dsl/v1/namespace_spec.rb b/lib/spec/kube-dsl/dsl/v1/namespace_spec.rb new file mode 100644 index 00000000..0e14341e --- /dev/null +++ b/lib/spec/kube-dsl/dsl/v1/namespace_spec.rb @@ -0,0 +1,19 @@ +require './lib/spec/spec_helper' + +describe KubeDSL::DSL::V1::Namespace do + subject(:object) { described_class.new } + + describe '#validate!' do + context 'when metadata is an object' do + specify do + expect(object.validate!).to be_truthy + end + end + + context 'when metadata is not an object' do + specify do + expect(object.validate!).to be_falsey + end + end + end +end diff --git a/lib/spec/spec_helper.rb b/lib/spec/spec_helper.rb new file mode 100644 index 00000000..5963d3ec --- /dev/null +++ b/lib/spec/spec_helper.rb @@ -0,0 +1,8 @@ +require 'bundler/setup' +Bundler.setup + +require 'kube-dsl' + +RSpec.configure do |config| + # some (optional) config here +end