Exemple #1
0
def test_reading_metadata_with_deprecated_fields_doesnt_crash(tmpdir):
    metadata_path = tmpdir / "synth.metadata"
    metadata_path.write_text(
        """
{
  "updateTime": "2020-01-28T12:42:19.618670Z",
  "newFiles": [
    {
      "path": ".eslintignore"
    }
  ]
}
""",
        "utf-8",
    )
    metadata._read_or_empty()
Exemple #2
0
def test_cwd_git_source_in_metadata(source_tree):
    # Instantiate a MetadataTrackerAndWriter to write the metadata.
    with metadata.MetadataTrackerAndWriter(source_tree.tmpdir /
                                           "synth.metadata"):
        pass
    mdata = metadata._read_or_empty(source_tree.tmpdir / "synth.metadata")
    cwd_source = mdata.sources[0].git
    assert cwd_source.name == "."
Exemple #3
0
def test_git_sources_are_sorted(source_tree: SourceTree):
    metadata_path = source_tree.tmpdir / "synth.metadata"
    with metadata.MetadataTrackerAndWriter(metadata_path):
        metadata.add_generator_source(name="a-generator",
                                      version="1",
                                      docker_image="x")
        metadata.add_generator_source(name="b-generator",
                                      version="2",
                                      docker_image="y")
        metadata.add_template_source(name="a-template",
                                     origin="andromeda",
                                     version="3")
        metadata.add_template_source(name="b-template",
                                     origin="milky way",
                                     version="4")
        metadata.add_git_source(name="a-git", sha="1a")
        metadata.add_git_source(name="b-git", sha="1b")
    m1 = metadata._read_or_empty(metadata_path)
    # Add the same sources in reverse order.
    metadata.reset()
    with metadata.MetadataTrackerAndWriter(metadata_path):
        metadata.add_git_source(name="b-git", sha="1b")
        metadata.add_git_source(name="a-git", sha="1a")
        metadata.add_template_source(name="b-template",
                                     origin="milky way",
                                     version="4")
        metadata.add_template_source(name="a-template",
                                     origin="andromeda",
                                     version="3")
        metadata.add_generator_source(name="b-generator",
                                      version="2",
                                      docker_image="y")
        metadata.add_generator_source(name="a-generator",
                                      version="1",
                                      docker_image="x")
    m2 = metadata._read_or_empty(metadata_path)
    assert m1.sources == m2.sources
Exemple #4
0
def test_used_to_append_git_log_to_metadata(source_tree):
    """Synthtool used to append the git log for each git source.  But nothing
    consumes the log, and there's no design for anything to consume the log.
    Plus, it cluttered up synth.metadata.
    """
    with metadata.MetadataTrackerAndWriter(source_tree.tmpdir /
                                           "synth.metadata"):
        # Create one commit that will be recorded in the metadata.
        source_tree.write("a")
        source_tree.git_add("a")
        source_tree.git_commit("a")

        hash = subprocess.run(
            [source_tree.git, "log", "-1", "--pretty=format:%H"],
            stdout=subprocess.PIPE,
            universal_newlines=True,
        ).stdout.strip()
        metadata.add_git_source(name="tmp", local_path=os.getcwd(), sha=hash)

    metadata.reset()
    with metadata.MetadataTrackerAndWriter(source_tree.tmpdir /
                                           "synth.metadata"):
        # Create two more commits that should appear in metadata git log.
        source_tree.write("code/b")
        source_tree.git_add("code/b")
        source_tree.git_commit("code/b")

        source_tree.write("code/c")
        source_tree.git_add("code/c")
        source_tree.git_commit("code/c")

        hash = subprocess.run(
            [source_tree.git, "log", "-1", "--pretty=format:%H"],
            stdout=subprocess.PIPE,
            universal_newlines=True,
        ).stdout.strip()
        metadata.add_git_source(name="tmp", local_path=os.getcwd(), sha=hash)

    # Read the metadata that we just wrote.
    mdata = metadata._read_or_empty(source_tree.tmpdir / "synth.metadata")
    # The log should be empty.
    assert "" == mdata.sources[1].git.log
    # Make sure the local path field is not recorded.
    assert not mdata.sources[0].git.local_path is None
Exemple #5
0
def test_append_git_log_to_metadata(source_tree):
    with metadata.MetadataTrackerAndWriter(source_tree.tmpdir / "synth.metadata"):
        # Create one commit that will be recorded in the metadata.
        source_tree.write("a")
        source_tree.git_add("a")
        source_tree.git_commit("a")

        hash = subprocess.run(
            [source_tree.git, "log", "-1", "--pretty=format:%H"],
            stdout=subprocess.PIPE,
            universal_newlines=True,
        ).stdout.strip()
        metadata.add_git_source(name="tmp", local_path=os.getcwd(), sha=hash)

    metadata.reset()
    with metadata.MetadataTrackerAndWriter(source_tree.tmpdir / "synth.metadata"):
        # Create two more commits that should appear in metadata git log.
        source_tree.write("code/b")
        source_tree.git_add("code/b")
        source_tree.git_commit("code/b")

        source_tree.write("code/c")
        source_tree.git_add("code/c")
        source_tree.git_commit("code/c")

        hash = subprocess.run(
            [source_tree.git, "log", "-1", "--pretty=format:%H"],
            stdout=subprocess.PIPE,
            universal_newlines=True,
        ).stdout.strip()
        metadata.add_git_source(name="tmp", local_path=os.getcwd(), sha=hash)

    # Read the metadata that we just wrote.
    mdata = metadata._read_or_empty(source_tree.tmpdir / "synth.metadata")
    # Match 2 log lines.
    assert re.match(
        r"[0-9A-Fa-f]+\ncode/c\n+[0-9A-Fa-f]+\ncode/b\n+",
        mdata.sources[0].git.log,
        re.MULTILINE,
    )
    # Make sure the local path field is not recorded.
    assert not mdata.sources[0].git.local_path is None
def test_read_nonexistent_metadata(tmpdir):
    # The file doesn't exist.
    read_metadata = metadata._read_or_empty(tmpdir / "synth.metadata")
    metadata.reset()
    assert metadata.get() == read_metadata
def test_read_metadata(tmpdir):
    metadata.reset()
    add_sample_client_destination()
    metadata.write(tmpdir / "synth.metadata")
    read_metadata = metadata._read_or_empty(tmpdir / "synth.metadata")
    assert metadata.get() == read_metadata