Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor commands and add testing #72

Merged
merged 28 commits into from
Nov 27, 2018
Merged

Refactor commands and add testing #72

merged 28 commits into from
Nov 27, 2018

Conversation

eguzki
Copy link
Member

@eguzki eguzki commented Nov 7, 2018

  • Refactor copy service command
  • Refactor update service command
  • Add unit tests

@eguzki eguzki requested a review from mikz November 7, 2018 12:03
@eguzki eguzki closed this Nov 7, 2018
@eguzki eguzki reopened this Nov 7, 2018
@eguzki eguzki requested a review from davidor November 7, 2018 15:50
remote: remote(source))
copy_service = create_new_service(source_service.show_service, destination, system_name)
context = create_context(source_service, copy_service)
tasks = [Tasks::CopyServiceProxyTask.new(context),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a matter of style, but I think this is better for several reasons:

tasks = [ 
  ...,
  ...,
]

Copy link
Contributor

@mikz mikz Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, to enforce a uniform interface between them you can do:

COPY_SERVICE = [
  Tasks::CopyServiceProxyTask,
  Tasks::CopyMethodsTas,
  ...,
].freeze
COPY_SERVICE.map{ |task| task.new(context) }.each(&:call)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first try was to pass context to the call method.

tasks.each { |task| task.call(context) }

But later, I found convenient to have different context for each task. It turns out, so far, only one task needs extra param besides source/target service clients. I think this the most flexible way.

class UpdateServiceSettingsTask
attr_reader :source_service, :copy_service, :target_system_name

def initialize(source_service:, copy_service:, target_name:)
Copy link
Contributor

@mikz mikz Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When naming one source then the other should be target no? original/copy vs source/target.

copy_methods = copy_service.methods
puts "original service hits metric #{source_service.hits['id']} has #{source_methods.size} methods"
puts "copied service hits metric #{copy_service.hits['id']} has #{copy_methods.size} methods"
m_m = ThreeScaleToolbox::Helper.array_difference(source_methods, copy_methods) do |method, copy|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing missing_methods is not that big a deal.

@davidor davidor removed their request for review November 20, 2018 10:26
@eguzki
Copy link
Member Author

eguzki commented Nov 22, 2018

I am afraid, this PR is getting pretty big. Unfortunately, the refactor changes everything upside down into many pieces and each piece has its own unit test.

Not sure to include integration tests in this PR. Will wok on them and can be included in this PR or later in another PR

@eguzki
Copy link
Member Author

eguzki commented Nov 22, 2018

Import CSV command has not been refactored. No sure if it is useful and if anybody uses it.

@eguzki eguzki changed the title (WIP) refactor commands and add testing Refactor commands and add testing Nov 23, 2018
@eguzki
Copy link
Member Author

eguzki commented Nov 23, 2018

Opened another branch for integration tests.

This PR is ready for review @mikz

@eguzki eguzki merged commit 2feedce into master Nov 27, 2018
@eguzki eguzki deleted the command-tests branch November 27, 2018 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants