Skip to content

Commit

Permalink
Add test for generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha committed Nov 30, 2023
1 parent c916681 commit 0bda83e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/command/generate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require "spec_helper"
require "pathname"
require "rake"

GEM_ROOT_PATH = Pathname.new(Dir.pwd)
GEM_TEMP_PATH = GEM_ROOT_PATH.join("tmp")
GENERATOR_PLAYGROUND_PATH = GEM_TEMP_PATH.join("sample-project")
CONTROLPLANE_CONFIG_DIR_PATH = GENERATOR_PLAYGROUND_PATH.join(".controlplane")
CPL_EXECUTABLE_PATH = GEM_ROOT_PATH.join("bin", "cpl")

def sh_in_dir(dir, *shell_commands)
shell_commands.flatten.each { |shell_command| RakeFileUtils.sh %(cd '#{dir}' && #{shell_command.strip}) }
end

describe Command::Generate do
before do
FileUtils.rm_r(GENERATOR_PLAYGROUND_PATH) if Dir.exist?(GENERATOR_PLAYGROUND_PATH)
FileUtils.mkdir_p GENERATOR_PLAYGROUND_PATH
end

after do
FileUtils.rm_r GENERATOR_PLAYGROUND_PATH
end

context "when no configuration exist in the project" do
it "generates base config files" do
command = "#{CPL_EXECUTABLE_PATH} generate"
sh_in_dir(GENERATOR_PLAYGROUND_PATH, command)

controlplane_config_file_path = CONTROLPLANE_CONFIG_DIR_PATH.join("controlplane.yml")
expect(controlplane_config_file_path).to exist
end
end
end

0 comments on commit 0bda83e

Please sign in to comment.