Ejemplo n.º 1
0
def test_post_receive(git_dir):
    git_dir.chdir()
    head = dzonegit.get_head()
    revisions = "{} {} refs/heads/master\n".format(
        "0000000000000000000000000000000000000000",
        head,
    )
    stdin = StringIO(revisions)
    codir = git_dir.join("co")
    subprocess.call(["git", "config", "dzonegit.checkoutpath", str(codir)])
    subprocess.call([
        "git",
        "config",
        "dzonegit.reconfigcmd",
        "echo TEST >{}/test".format(codir),
    ])
    dzonegit.post_receive(stdin)
    assert codir.join("dummy.zone").check()
    assert codir.join("test").read() == "TEST\n"
    # Test reconfig after renaming the file
    codir.join("test").write("")
    subprocess.call(["git", "mv", "dummy.zone", "dummy.zone.old"])
    subprocess.call(["git", "commit", "-m", "rename dummy zone"])
    revisions = "{} {} refs/heads/master\n".format(
        head,
        dzonegit.get_head(),
    )
    stdin = StringIO(revisions)
    dzonegit.post_receive(stdin)
    assert codir.join("test").read() == "TEST\n"
Ejemplo n.º 2
0
def test_get_head(git_dir):
    git_dir.chdir()
    assert dzonegit.get_head() == "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
    git_dir.join("dummy").write("dummy\n")
    subprocess.call(["git", "add", "dummy"])
    subprocess.call(["git", "commit", "-m", "dummy"])
    assert dzonegit.get_head() != "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
Ejemplo n.º 3
0
def test_check_whitespace_errors(git_dir):
    git_dir.chdir()
    git_dir.join("whitespace").write(" ")
    subprocess.call(["git", "add", "whitespace"])
    with pytest.raises(ValueError):
        dzonegit.check_whitespace_errors(dzonegit.get_head())
    subprocess.call(["git", "commit", "-m", "whitespace"])
    with pytest.raises(ValueError):
        dzonegit.check_whitespace_errors("HEAD~", dzonegit.get_head())
    subprocess.call(["git", "rm", "-f", "whitespace"])
    subprocess.call(["git", "commit", "-m", "rm whitespace"])
    dzonegit.check_whitespace_errors(dzonegit.get_head())
    dzonegit.check_whitespace_errors("HEAD~", dzonegit.get_head())
Ejemplo n.º 4
0
def test_pre_receive(git_dir):
    git_dir.chdir()
    revisions = "{} {} ".format(
        "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
        dzonegit.get_head(),
    )
    stdin = StringIO(revisions + "refs/heads/slave\n")
    with pytest.raises(SystemExit):
        dzonegit.pre_receive(stdin)
    stdin = StringIO(revisions + "refs/heads/master\n")
    dzonegit.pre_receive(stdin)
Ejemplo n.º 5
0
def test_update(git_dir):
    git_dir.chdir()
    os.environ.update({"GIT_DIR": str(git_dir.join(".git"))})
    with pytest.raises(SystemExit):
        dzonegit.update(["update", "refs/heads/slave", "0", "0"])
    dzonegit.update([
        "update",
        "refs/heads/master",
        "0" * 40,
        dzonegit.get_head(),
    ])
Ejemplo n.º 6
0
def test_check_updated_zones(git_dir):
    git_dir.chdir()
    git_dir.join("dummy.zone").write("")
    subprocess.call(["git", "add", "dummy.zone"])
    with pytest.raises(ValueError):
        dzonegit.check_updated_zones(dzonegit.get_head())
    subprocess.call(["git", "commit", "-m", "empty dummy.zone"])
    with pytest.raises(ValueError):
        dzonegit.check_updated_zones("HEAD~", "HEAD")
    git_dir.join("dummy.zone").write("""
@ 60 IN SOA ns hm 1 60 60 60 60
  60 NS ns.example.com.
""")
    subprocess.call(["git", "add", "dummy.zone"])
    dzonegit.check_updated_zones(dzonegit.get_head())
    subprocess.call(["git", "commit", "-m", "dummy.zone"])
    dzonegit.check_updated_zones("HEAD~", "HEAD")
    git_dir.join("dummy.zone").write("""
@ 60 IN SOA ns hm 1 60 60 60 60
  60 NS ns.example.org.
""")
    subprocess.call(["git", "add", "dummy.zone"])
    with pytest.raises(ValueError):
        dzonegit.check_updated_zones(dzonegit.get_head())
    subprocess.call(["git", "commit", "-m", "updated dummy.zone"])
    with pytest.raises(ValueError):
        dzonegit.check_updated_zones("HEAD~", "HEAD")
    git_dir.join("dummy.zone").write("""
$ORIGIN other.
@ 60 IN SOA ns hm 1 60 60 60 60
  60 NS ns.example.org.
""")
    subprocess.call(["git", "add", "dummy.zone"])
    with pytest.raises(ValueError):
        dzonegit.check_updated_zones(dzonegit.get_head())
    git_dir.join("dummy.zone").write("""
$ORIGIN dummy.
@ 60 IN SOA ns hm 1 61 60 60 60
  60 NS ns.example.org.
""")
    subprocess.call(["git", "add", "dummy.zone"])
    with pytest.raises(ValueError):
        dzonegit.check_updated_zones("HEAD", autoupdate_serial=True)
    subprocess.call(["git", "add", "dummy.zone"])
    dzonegit.check_updated_zones(dzonegit.get_head())
    git_dir.join("dummy.zone").write("""
$ORIGIN dummy.
@ 60 IN SOA ns hm $UNIXTIME 61 60 60 60
  60 NS ns.example.org.
""")
    subprocess.call(["git", "add", "dummy.zone"])
    dzonegit.check_updated_zones(dzonegit.get_head())
    subprocess.call(["git", "commit", "-m", "dummy.zone with $UNIXTIME"])
    git_dir.join("dummy.zone").write("""
$ORIGIN dummy.
@ 60 IN SOA ns hm 1 60 60 60 60
  60 NS ns.example.org.
""")
    subprocess.call(["git", "add", "dummy.zone"])
    with pytest.raises(ValueError):
        dzonegit.check_updated_zones(dzonegit.get_head())
    git_dir.join("dummy.zone").write("""
$ORIGIN dummy.
@ 60 IN SOA ns hm $UNIXTIME 60 60 60 60
  60 NS ns.example.org.
""")
    subprocess.call(["git", "add", "dummy.zone"])
    dzonegit.check_updated_zones(dzonegit.get_head())
    subprocess.call(["git", "commit", "-m", "final dummy.zone"])
    dzonegit.check_updated_zones("HEAD~", "HEAD")