def test_secret_env_edit(): run(lain, args=['env', 'edit']) res = run(lain, args=['env', 'show']) modified_env = yalo(res.output) # the original data will be preserved assert 'FOO' in modified_env['data'] # our fake $EDITOR will write a key called SURPRISE assert 'SURPRISE' in modified_env['data'] res = run(lain, args=['secret', 'edit']) res = run(lain, args=['secret', 'show']) modified_secret = yalo(res.output) assert 'topsecret.txt' in modified_secret['data'] assert 'SURPRISE' in modified_secret['data']
def test_ya(): dic = {'slogan': BULLSHIT} f = NamedTemporaryFile() yadu(dic, f) f.seek(0) assert yalo(f) == dic multiline_content = {'so': LiteralScalarString('so\nlong')} s = yadu(multiline_content) # should dump multiline string in readable format assert ': |' in s
def test_lain_init_with_values_j2(): values_j2 = f'{CHART_DIR_NAME}/values.yaml.j2' j2 = 'appname: {{ appname }}' with open(values_j2, 'w') as f: f.write(j2) res = run(lain, args=['init'], returncode=1) assert 'already exists' in res.output run(lain, args=['--ignore-lint', 'init', '-f']) values = yalo(DUMMY_VALUES_PATH) assert values == {'appname': DUMMY_APPNAME}
def test_tell_all_clusters(mocker): test_cluster_values_file = f'values-{TEST_CLUSTER}.yaml' # we need at least two clusters to verify that tell_all_clusters are working correctly another_cluster_name = 'another' another_cluster_values_file = f'values-{another_cluster_name}.yaml' tempd = TemporaryDirectory() test_cluster_values_path = join(CLUSTER_VALUES_DIR, test_cluster_values_file) test_cluster_values = yalo(test_cluster_values_path) test_cluster_values['registry'] = 'another.example.com' shutil.copyfile(test_cluster_values_path, join(tempd.name, test_cluster_values_file)) yadu(test_cluster_values, join(tempd.name, another_cluster_values_file)) mocker.patch('lain_cli.utils.KUBECONFIG_DIR', tempd.name) mocker.patch('lain_cli.utils.CLUSTER_VALUES_DIR', tempd.name) # touch kubeconfig-another Path(join(tempd.name, f'kubeconfig-{another_cluster_name}')).write_text('') Path(join(tempd.name, f'kubeconfig-{TEST_CLUSTER}')).write_text('') # now that kubeconfig and cluster values file are present, we can verify # CLUSTERS is correct _, ccs = run_under_click_context(tell_all_clusters, ) assert set(ccs) == {TEST_CLUSTER, another_cluster_name} assert ccs['another']['registry'] == test_cluster_values['registry'] tempd.cleanup()
def load_dummy_values(): with open(DUMMY_VALUES_PATH) as f: values = yalo(f) return values
def render_k8s_specs(): res = run(lain, args=['-s', 'template']) return list(yalo(res.stdout, many=True))