This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
id2attrpath | ||
is_sqlite3 | ||
pkgdb | ||
semver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /usr/bin/env bats | ||
# -*- mode: bats; -*- | ||
# ============================================================================ # | ||
# | ||
# `id2attrpath' executable tests. | ||
# | ||
# ---------------------------------------------------------------------------- # | ||
|
||
load setup_suite.bash; | ||
|
||
# bats file_tags=id2attrpath | ||
|
||
|
||
# ---------------------------------------------------------------------------- # | ||
|
||
setup_file() { | ||
export DBPATH="$BATS_FILE_TMPDIR/test-cli.sqlite"; | ||
mkdir -p "$BATS_FILE_TMPDIR"; | ||
# We don't parallelize these to avoid DB sync headaches and to recycle the | ||
# cache between tests. | ||
# Nonetheless this file makes an effort to avoid depending on past state in | ||
# such a way that would make it difficult to eventually parallelize in | ||
# the future. | ||
export BATS_NO_PARALLELIZE_WITHIN_FILE=true; | ||
export TEST_HARNESS_FLAKE="$TESTS_DIR/harnesses/proj0"; | ||
# Load a database to query during testing | ||
"$PKGDB" scrape --database "$DBPATH" "$TEST_HARNESS_FLAKE" packages "$NIX_SYSTEM"; | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------- # | ||
|
||
@test "retrieves existing attrset" { | ||
run "$ID2ATTRPATH" "$DBPATH" 2; | ||
assert_output "packages $NIX_SYSTEM"; | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------- # | ||
|
||
@test "error on nonexistent attrset" { | ||
run "$ID2ATTRPATH" "$DBPATH" 3; | ||
assert_failure; | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------- # | ||
# | ||
# | ||
# | ||
# ============================================================================ # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* ========================================================================== * | ||
* | ||
* @file tests/id2attrpath.cc | ||
* | ||
* @brief Minimal executable to return the attribute path given an attrset id. | ||
* | ||
* | ||
* -------------------------------------------------------------------------- */ | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <cstdlib> | ||
|
||
#include "flox/util.hh" | ||
#include "pkgdb.hh" | ||
|
||
|
||
/* -------------------------------------------------------------------------- */ | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
if (argc < 2) | ||
{ | ||
std::cout << "usage: id2attrpath SOURCE ID" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
std::string source( argv[1] ); | ||
std::string idStr( argv[2] ); | ||
|
||
/* Attempt to parse the id to an int */ | ||
flox::pkgdb::row_id id; | ||
try | ||
{ | ||
id = std::stoull( idStr ); | ||
} | ||
catch( const std::exception & e ) | ||
{ | ||
std::cerr << "Couldn't convert 'id' to 'int'" << std::endl; | ||
std::cerr << e.what() << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
/* Act on the source (database vs. flake ref) */ | ||
if ( flox::isSQLiteDb( source ) ) | ||
{ | ||
flox::pkgdb::PkgDb db = flox::pkgdb::PkgDb( source ); | ||
flox::AttrPath attrPath; | ||
/* The user-provided id may not be in the database */ | ||
try | ||
{ | ||
attrPath = db.getAttrSetPath( id ); | ||
} | ||
catch ( const std::exception & e ) | ||
{ | ||
std::cerr << "Failed to retrieve attrpath with id " << id << std::endl; | ||
std::cerr << e.what() << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
for (unsigned long i = 0; i < attrPath.size() - 1; i++) | ||
{ | ||
std::cout << attrPath[i] << " "; | ||
} | ||
std::cout << attrPath[attrPath.size() - 1] << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "flake references aren't a supported source yet" | ||
<< std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
|
||
/* -------------------------------------------------------------------------- * | ||
* | ||
* | ||
* | ||
* ========================================================================== */ |