github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/test/install/github_test.sh (about)

     1  . test_harness.sh
     2  
     3  # check that we can extract single json values
     4  test_extract_json_value() {
     5    fixture=./test-fixtures/github-api-buildx-v0.36.0-release.json
     6    content=$(cat ${fixture})
     7  
     8    actual=$(extract_json_value "${content}" "tag_name")
     9    assertEquals "v0.36.0" "${actual}" "unable to find tag_name"
    10  
    11    actual=$(extract_json_value "${content}" "id")
    12    assertEquals "57501596" "${actual}" "unable to find tag_name"
    13  }
    14  
    15  run_test_case test_extract_json_value
    16  
    17  
    18  # check that we can extract github release tag from github api json
    19  test_github_release_tag() {
    20    fixture=./test-fixtures/github-api-buildx-v0.36.0-release.json
    21    content=$(cat ${fixture})
    22  
    23    actual=$(github_release_tag "${content}")
    24    assertEquals "v0.36.0" "${actual}" "unable to find release tag"
    25  }
    26  
    27  run_test_case test_github_release_tag
    28  
    29  
    30  # download a known good github release checksums and compare against a test-fixture
    31  test_download_github_release_checksums() {
    32    tmpdir=$(mktemp -d)
    33  
    34    tag=v0.36.0
    35    github_download="https://github.com/metasources/buildx/releases/download/${tag}"
    36    name=${PROJECT_NAME}
    37    version=$(tag_to_version "${tag}")
    38  
    39    actual_filepath=$(download_github_release_checksums "${github_download}" "${name}" "${version}" "${tmpdir}")
    40    assertFilesEqual \
    41      "./test-fixtures/buildx_0.36.0_checksums.txt" \
    42      "${actual_filepath}" \
    43      "unable to find release tag"
    44  
    45    rm -rf -- "$tmpdir"
    46  }
    47  
    48  run_test_case test_download_github_release_checksums
    49  
    50  
    51  # download a checksums file from a locally served-up snapshot directory and compare against the file in the snapshot dir
    52  test_download_github_release_checksums_snapshot() {
    53    tmpdir=$(mktemp -d)
    54  
    55    github_download=$(snapshot_download_url)
    56    name=${PROJECT_NAME}
    57    version=$(snapshot_version)
    58  
    59    actual_filepath=$(download_github_release_checksums "${github_download}" "${name}" "${version}" "${tmpdir}")
    60    assertFilesEqual \
    61      "$(snapshot_checksums_path)" \
    62      "${actual_filepath}" \
    63      "unable to find release tag"
    64  
    65    rm -rf -- "$tmpdir"
    66  }
    67  
    68  run_test_case_with_snapshot_release test_download_github_release_checksums_snapshot