<commit_before>require_relative 'app_lib_test_base'

class PullerServiceTest < AppLibTestBase

  # These will fail if there is no network connectivity.

  def setup
    super
    set_puller_class('PullerService')
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'D4FCD3',
  'smoke test puller.pull(nil) raises' do
    error = assert_raises { puller.pull(nil) }
    assert error.message.start_with? 'PullerService:pull:docker pull'
  end

  test 'D4FCD4',
  'smoke test puller.pulled?(nil) returns false' do
    refute puller.pulled?(nil)
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'D4F808',
  'smoke test puller-service' do
    refute puller.pulled? 'cyberdojo/non_existant'
    image_name = 'cyberdojofoundation/gcc_assert'
    assert puller.pull image_name
    assert puller.pulled? image_name
  end

end<commit_msg>updated puller-service tests now that puller validates the image_name arguments<commit_after>require_relative 'app_lib_test_base'

class PullerServiceTest < AppLibTestBase

  # These will fail if there is no network connectivity.

  test 'D4F808',
  'smoke test puller' do
    refute puller.pulled? 'cyberdojo/non_existant'
    image_name = 'cyberdojofoundation/gcc_assert'
    assert puller.pull image_name
    assert puller.pulled? image_name
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'D4FCD3',
  'smoke test pulled?() raises for invalid image_name' do
    invalid_image_names.each do |invalid_image_name|
      assert_raises_invalid_image('pulled?') {
        puller.pulled?(invalid_image_name)
      }
    end
  end

  test 'D4FCD4',
  'smoke test pull() raises for invalid image_name' do
    invalid_image_names.each do |invalid_image_name|
      assert_raises_invalid_image('pull') {
        puller.pull(invalid_image_name)
      }
    end
  end

  private

  def assert_raises_invalid_image(method)
    error = assert_raises { yield }
    expected = "PullerService:#{method}:image_name:invalid"
    assert error.message.start_with?(expected), error.message
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - -

  def invalid_image_names
    [
      '',             # nothing!
      '_',            # cannot start with separator
      'name_',        # cannot end with separator
      'ALPHA/name',   # no uppercase
      'alpha/name_',  # cannot end in separator
      'alpha/_name',  # cannot begin with separator
    ]
  end

end
{'fraction_non_alphanumeric': 0.1188037689471528, 'fraction_numerical': 0.006554690700532569, 'mean_word_length': 2.3822714681440442, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7539937', 'n_tokens_mistral': 878, 'n_tokens_neox': 849, 'n_words': 181}