Skip to content

Commit

Permalink
extract fup running test method
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Dec 9, 2023
1 parent 224965c commit bd33b36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
version = "0.18.3"
version = "0.18.4"
)

type args struct {
Expand Down
18 changes: 18 additions & 0 deletions tests/fup_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import shlex
import subprocess
import yaml


def run_fup(config: dict, config_file: str, provisioner: str) -> int:
config_dir = os.path.dirname(config_file)
if not os.path.exists(config_dir):
os.mkdir(config_dir)

with open(config_file, 'wt') as fd:
yaml.dump(config, Dumper=yaml.SafeDumper, stream=fd)

go_path = os.getenv('GOPATH', os.path.expanduser('~/go'))
fup_bin = os.path.join(go_path, 'bin', 'fup')
cmd = shlex.split(f'{fup_bin} -p {provisioner} -f {config_file} -l 0 -n')
return subprocess.run(cmd).returncode
16 changes: 3 additions & 13 deletions tests/test_archives.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import dataclasses
import os
import shlex
import shutil
import subprocess
import sys
import unittest

import yaml
import fup_test

ABSOLUTE_ARTIFACTS_DIR = os.path.expanduser('~/out')
RELATIVE_ARTIFACTS_DIR = 'out'
Expand Down Expand Up @@ -130,16 +128,8 @@ def test(self):

artifacts_dir = RELATIVE_ARTIFACTS_DIR if test_case.relative else ABSOLUTE_ARTIFACTS_DIR

if not os.path.exists(artifacts_dir):
os.mkdir(artifacts_dir)
with open(f'{artifacts_dir}/fup.yml', 'wt') as fd:
yaml.dump(config, Dumper=yaml.SafeDumper, stream=fd)

go_path = os.getenv('GOPATH', os.path.expanduser('~/go'))
fup_bin = os.path.join(go_path, 'bin', 'fup')
cmd = shlex.split(f'{fup_bin} -p archive -f {artifacts_dir}/fup.yml -l 0 -n')
proc = subprocess.run(cmd)
self.assertTrue(proc.returncode == 0)
return_code = fup_test.run_fup(config, f'{artifacts_dir}/fup.yml', 'archive')
self.assertTrue(return_code == 0)

link_name = ensure_abs(test_case.symlink.link_name, artifacts_dir)
target = ensure_abs(test_case.symlink.target, artifacts_dir)
Expand Down

0 comments on commit bd33b36

Please sign in to comment.