Exemplo n.º 1
0
def test_str(tmpdir):
    """
    Verifies the string representation is exactly the same as the
    instance dict.
    """
    m = meta.GenericBuildMeta(_create_test_files(tmpdir), '1.2.3')
    assert dict(m) == json.loads(str(m))
Exemplo n.º 2
0
def test_invalid_schema(tmpdir):
    """
    Verifies that schema testing is enforced and checked against a known-good
    meta.json.
    """
    with pytest.raises(ValidationError):
        _ = meta.GenericBuildMeta(_create_test_files(tmpdir), '1.2.3')
Exemplo n.º 3
0
def test_valid_schema(tmpdir):
    """
    Verifies that schema testing is enforced and checked against a known-good
    meta.json.
    """
    for meta_f in os.listdir(TEST_META_PATH):
        print(f"Validating {meta_f}")
        test_meta = os.path.join(TEST_META_PATH, meta_f)
        with open(test_meta, 'r') as valid_data:
            td = json.load(valid_data)
            _ = meta.GenericBuildMeta(_create_test_files(tmpdir, meta_data=td),
                                      '1.2.3')
Exemplo n.º 4
0
def test_set(tmpdir):
    """
    Verify setting works as expected.
    """
    m = meta.GenericBuildMeta(_create_test_files(tmpdir), '1.2.3')
    m.set('test', 'changed')
    m.write()
    assert m.get('test') == 'changed'
    m.set(['a', 'b'], 'z')
    m.write()
    assert m.get(['a', 'b']) == 'z'
    assert m['a']['b'] == 'z'
    with pytest.raises(Exception):
        m.set(['i', 'donot', 'exist'], 'boom')
Exemplo n.º 5
0
def test_get(tmpdir):
    m = meta.GenericBuildMeta(_create_test_files(tmpdir), '1.2.3')
    assert m.get('test') == 'data'
    assert m.get('nope', 'default') == 'default'
    assert m.get(['a', 'b']) == 'c'
    assert m.get(['a', 'd'], 'nope') == 'nope'
Exemplo n.º 6
0
def test_init(tmpdir):
    m = meta.GenericBuildMeta(_create_test_files(tmpdir), '1.2.3')
    assert m['test'] is not None
Exemplo n.º 7
0
def test_merge_meta(tmpdir):
    """
    Verifies merging meta.json works as expected.
    """
    x = None
    y = None

    aws = {
        "path":
        "/dev/null",
        "size":
        99999999,
        "sha256":
        "ff279bc0207964d96571adfd720b1af1b65e587e589eee528d0315b7fb298773"
    }

    def get_aws(x, key="path"):
        return x.get("images", {}).get("aws", {}).get(key)

    for meta_f in os.listdir(TEST_META_PATH):
        test_meta = os.path.join(TEST_META_PATH, meta_f)
        with open(test_meta, 'r') as valid_data:
            td = json.load(valid_data)
            m = meta.GenericBuildMeta(_create_test_files(tmpdir, meta_data=td),
                                      '1.2.3')

            w = meta.GenericBuildMeta(_create_test_files(tmpdir, meta_data=td),
                                      '1.2.3')
            # create working copies
            if x is None:
                x = copy.deepcopy(m)
            else:
                y = copy.deepcopy(m)

            # add the stamp
            m.write()
            old_stamp = m.get(meta.COSA_VER_STAMP)
            assert old_stamp is not None

            # check merging old into new
            m["images"]["aws"] = aws
            m[meta.COSA_VER_STAMP] = 10

            m.write()
            new_stamp = m.get(meta.COSA_VER_STAMP)
            assert new_stamp > old_stamp
            assert get_aws(m) != aws["path"]

    # Now go full yolo and attempt to merge RHCOS into FCOS
    # Srly? Whose going to do this...
    y._meta_path = x.path
    with pytest.raises(meta.COSAMergeError):
        x.write()

    #### Artifact merging tests
    # clear the meta.json that's been corrupted
    os.unlink(x.path)

    # test that write went to meta.json
    maws = x.write()
    assert x.path == maws

    # test that write went to meta.aws.json
    x.set("coreos-assembler.delayed-meta-merge", True)
    maws = x.write(artifact_name="aws")
    assert maws.endswith("aws.json")

    # make sure that meta.json != meta.aws.json
    x.read()
    d = load_json(maws)
    assert get_aws(m) != get_aws(d)

    # test that the write went to meta.<TS>.json
    tnw = x.write()
    assert maws != tnw
Exemplo n.º 8
0
def test_get(tmpdir):
    m = meta.GenericBuildMeta(_create_test_files(tmpdir), '1.2.3')
    assert m.get('test') == 'data'
    assert m.get('a', 'b') == 'c'
    with pytest.raises(KeyError):
        m.get('i', 'donot', 'exist')