Unverified Commit e13779d0 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Add new module for storing build metadata (#593)

Add new module for storing build metadata
parent 9911a265
# variable shared by this whole module
BUILD_DATA_FILE=""
bd_create() {
local cache_dir="$1"
BUILD_DATA_FILE="$cache_dir/build-data/node"
kv_create $BUILD_DATA_FILE
}
bd_get() {
kv_get $BUILD_DATA_FILE "$1"
}
bd_set() {
kv_set $BUILD_DATA_FILE "$1" "$2"
}
log_build_data() {
# print all values on one line in logfmt format
# https://brandur.org/logfmt
echo $(kv_list $BUILD_DATA_FILE)
}
...@@ -148,6 +148,26 @@ testKeyValueNoFile() { ...@@ -148,6 +148,26 @@ testKeyValueNoFile() {
assertEquals "$(kv_list $space)" "" assertEquals "$(kv_list $space)" ""
} }
testBuildData() {
local cache_dir=$(mktemp -d)
bd_create $cache_dir
bd_set "test" "foo"
assertEquals "test=foo" "$(log_build_data)"
bd_set "test" "different-foo"
assertEquals "test=different-foo" "$(log_build_data)"
bd_set "foo" "value with spaces"
assertEquals "foo=\"value with spaces\" test=different-foo" "$(log_build_data)"
# values are printed with the keys sorted alphabetically
# this isn't required, and this test serves as documentation
bd_set "a" "this should come first"
assertEquals "a=\"this should come first\" foo=\"value with spaces\" test=different-foo" "$(log_build_data)"
}
# mocks # mocks
source "$(pwd)"/test/mocks/stdlib.sh source "$(pwd)"/test/mocks/stdlib.sh
...@@ -155,6 +175,7 @@ source "$(pwd)"/test/mocks/stdlib.sh ...@@ -155,6 +175,7 @@ source "$(pwd)"/test/mocks/stdlib.sh
source "$(pwd)"/lib/monitor.sh source "$(pwd)"/lib/monitor.sh
source "$(pwd)"/lib/output.sh source "$(pwd)"/lib/output.sh
source "$(pwd)"/lib/kvstore.sh source "$(pwd)"/lib/kvstore.sh
source "$(pwd)"/lib/build-data.sh
# import the testing framework # import the testing framework
source "$(pwd)"/test/shunit2 source "$(pwd)"/test/shunit2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment