Skip to content

Commit

Permalink
with_terraform instead generate_terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
claytongentry committed Nov 26, 2024
1 parent 50b037b commit 30030dc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/manifold/api/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def workspaces
@workspaces ||= workspace_directories.map { |dir| Workspace.from_directory(dir, logger:) }
end

def generate(generate_terraform: false)
workspaces.each { |w| w.generate(generate_terraform:) }
generate_terraform_entrypoint if generate_terraform
def generate(with_terraform: false)
workspaces.each { |w| w.generate(with_terraform:) }
generate_terraform_entrypoint if with_terraform
end

def workspaces_directory
Expand Down
6 changes: 3 additions & 3 deletions lib/manifold/api/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def add
FileUtils.cp(template_path, manifold_path)
end

def generate(generate_terraform: false)
def generate(with_terraform: false)
return unless manifold_exists? && any_vectors?

generate_dimensions
do_generate_terraform if generate_terraform
generate_terraform if with_terraform
logger.info("Generated BigQuery dimensions table schema for workspace '#{name}'.")
end

Expand Down Expand Up @@ -101,7 +101,7 @@ def vectors
manifold_yaml["vectors"]
end

def do_generate_terraform
def generate_terraform
config = Terraform::WorkspaceConfiguration.new(name)
config.write(terraform_main_path)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/manifold/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def generate
path = Pathname.pwd
name = path.basename.to_s
project = API::Project.new(name, directory: path, logger:)
project.generate(generate_terraform: options[:tf])
project.generate(with_terraform: options[:tf])
logger.info "Generated BigQuery schema for all workspaces in the project."
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/manifold/api/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@
end
end

context "with generate_terraform: false" do
context "with with_terraform: false" do
it "does not generate terraform configurations" do
project.generate(generate_terraform: false)
project.generate(with_terraform: false)
expect(project.directory.join("main.tf.json")).not_to be_file
end
end

context "with generate_terraform: true" do
context "with with_terraform: true" do
it "creates a terraform configuration file" do
project.generate(generate_terraform: true)
project.generate(with_terraform: true)
expect(project.directory.join("main.tf.json")).to be_file
end

it "includes workspace modules in the terraform configuration" do
project.generate(generate_terraform: true)
project.generate(with_terraform: true)
config = parse_terraform_config(project)
expect(config["module"]).to include(expected_workspace_modules)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/manifold/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@

context "when called with --tf option" do
before do
allow(mock_project).to receive(:generate).with(generate_terraform: true)
allow(mock_project).to receive(:generate).with(with_terraform: true)
end

it "generates terraform configurations" do
cli.options = { tf: true }
cli.generate
expect(mock_project).to have_received(:generate).with(generate_terraform: true)
expect(mock_project).to have_received(:generate).with(with_terraform: true)
end
end

context "when called without --tf option" do
before do
allow(mock_project).to receive(:generate).with(generate_terraform: false)
allow(mock_project).to receive(:generate).with(with_terraform: false)
end

it "does not generate terraform configurations" do
cli.options = { tf: false }
cli.generate
expect(mock_project).to have_received(:generate).with(generate_terraform: false)
expect(mock_project).to have_received(:generate).with(with_terraform: false)
end
end
end
Expand Down

0 comments on commit 30030dc

Please sign in to comment.