예제 #1
0
def test_build_file_nb_ignored_tags():
    filepath = '{}/tags-test.ipynb'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    name, config, code = build_file(filepath)
    print("code:", code)
    assert code.find("import nuclio") > 0, "missing code section"
    assert code.find("test1") == -1, "did not ignore 'nuclio-ignore' (default)"

    name, config, code = build_file(filepath, ignored_tags="my-ignore-tag")
    print("code:", code)
    assert code.find("import nuclio") > 0, "missing code section"
    assert code.find("test3") == -1, "did not ignore 'my-ignore-tag'"
예제 #2
0
def test_build_url():
    filepath = 'https://raw.githubusercontent.com/nuclio/nuclio/master/hack/' \
               + 'examples/java/empty/EmptyHandler.java'

    name, config, code = build_file(filepath, name='javatst', output_dir='.')

    assert name == 'javatst', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)
    assert get_in(config, 'spec.runtime') == 'java', 'not java runtime'
예제 #3
0
def test_build_file_nb():
    filepath = '{}/handler.ipynb'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(config={'spec.maxReplicas': 2})
    name, config, code = build_file(filepath, spec=spec)

    assert name == 'handler', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)

    maxRep = get_in(config, 'spec.maxReplicas')
    assert maxRep == 2, 'failed to set replicas, {}'.format(maxRep)
예제 #4
0
def test_build_url(url_filepath):
    name, config, code = build_file(url_filepath,
                                    name='javatst',
                                    output_dir='.')

    assert name == 'javatst', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)
    assert get_in(config, 'spec.runtime') == 'java', 'not java runtime'
    assert os.path.exists('EmptyHandler.java'), \
        'EmptyHandler.java file was not created'
    assert os.path.exists('function.yaml'), \
        'function.yaml file was not created'
예제 #5
0
def test_build_file_zip(project):
    filepath = '{}/handler.py'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(env={'MYENV': 'text'})
    name, config, code = build_file(filepath, name='hw', spec=spec,
                                    archive=True, project=project, tag='v7',
                                    output_dir='.')

    assert name == 'hw', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)
    assert os.path.exists(project), '{} dir was not created'.format(project)
    zip_path = os.path.join(project, 'hw_v7.zip')
    assert os.path.exists(zip_path), '{} dir was not created'.format(zip_path)
예제 #6
0
def test_build_file_zip():
    filepath = '{}/handler.py'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(env={'MYENV': 'text'})
    name, config, code = build_file(filepath,
                                    name='hw',
                                    spec=spec,
                                    archive=True,
                                    project='p1',
                                    tag='v7',
                                    output_dir='.')

    assert name == 'hw', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)
예제 #7
0
def test_build_file_py():
    filepath = '{}/handler.py'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(env={'MYENV': 'text'})
    name, config, code = build_file(filepath, name='hw', spec=spec, tag='v7')

    assert name == 'hw', 'build failed, name doesnt match={}'.format(name)

    assert config.get('spec'), 'build failed, config={}'.format(config)

    tag = config['metadata']['labels'].get(meta_keys.tag)
    assert tag == 'v7', 'failed, tag not set properly config={}'.format(config)

    envs = config['spec']['env']
    assert envs[0].get('name') == 'MYENV', 'build failed, env err'.format(envs)