Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-nodejs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-nodejs
Commits
d7892f08
Unverified
Commit
d7892f08
authored
Feb 14, 2019
by
Jeremy Morrell
Committed by
GitHub
Feb 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add uuid utility (#618)
Adds a cross-platform compatible command to generate `uuid`s
parent
6f065b32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
uuid.sh
lib/uuid.sh
+47
-0
unit
test/unit
+30
-0
No files found.
lib/uuid.sh
0 → 100644
View file @
d7892f08
#!/usr/bin/env bash
uuid_fallback
()
{
local
N B
C
=
'89ab'
for
((
N
=
0
;
N < 16
;
++N
))
do
B
=
$((
RANDOM%256
))
case
$N
in
6
)
printf
'4%x'
$((
B%16
))
;;
8
)
printf
'%c%x'
${
C
:
$RANDOM
%
${#
C
}
:1
}
$((
B%16
))
;;
3
|
5
|
7
|
9
)
printf
'%02x-'
$B
;;
*
)
printf
'%02x'
$B
;;
esac
done
echo
}
uuid
()
{
# On Heroku's stack, there is a uuid command
if
[[
-f
/proc/sys/kernel/random/uuid
]]
;
then
cat
/proc/sys/kernel/random/uuid
# on macOS there is also a command
elif
[[
-x
"
$(
command
-v
uuidgen
)
"
]]
;
then
uuidgen |
tr
"[:upper:]"
"[:lower:]"
# If you are running this buildpack on an image without either of the above binaries
# then let's provide something that approximates this functionality, but beware that
# we can make no guarantees of true randomness or uniqueness of this ID. However it is
# likely only being piped to /dev/null
#
# If that's not true for you, please file an issue and let us know:
# https://github.com/heroku/heroku-buildpack-nodejs/issues
else
uuid_fallback
fi
}
test/unit
View file @
d7892f08
...
@@ -260,6 +260,34 @@ testWebConcurrencyProfileScript() {
...
@@ -260,6 +260,34 @@ testWebConcurrencyProfileScript() {
assertEquals
"1"
"
$(
calculate_concurrency 512 1
)
"
assertEquals
"1"
"
$(
calculate_concurrency 512 1
)
"
}
}
isUUID
()
{
if
[[
${
1
//-/
}
=
~ ^[[:xdigit:]]
{
32
}
$
]]
;
then
echo true
else
echo false
fi
}
testUUID
()
{
local
first second
first
=
$(
uuid
)
second
=
$(
uuid
)
assertNotEquals
"
$first
"
"
$second
"
assertEquals
"true"
"
$(
isUUID
"
$first
"
)
"
assertEquals
"true"
"
$(
isUUID
"
$second
"
)
"
}
testUUIDFallback
()
{
local
first second
first
=
$(
uuid_fallback
)
second
=
$(
uuid_fallback
)
assertNotEquals
"
$first
"
"
$second
"
assertEquals
"true"
"
$(
isUUID
"
$first
"
)
"
assertEquals
"true"
"
$(
isUUID
"
$second
"
)
"
}
testHasScript
()
{
testHasScript
()
{
local
file
=
"
$(
pwd
)
/test/fixtures/has-script-fixtures/package.json"
local
file
=
"
$(
pwd
)
/test/fixtures/has-script-fixtures/package.json"
assertEquals
"true"
"
$(
has_script
"
$file
"
"build"
)
"
assertEquals
"true"
"
$(
has_script
"
$file
"
"build"
)
"
...
@@ -274,6 +302,8 @@ BP_DIR="$(pwd)"
...
@@ -274,6 +302,8 @@ BP_DIR="$(pwd)"
source
"
$(
pwd
)
"
/test/mocks/stdlib.sh
source
"
$(
pwd
)
"
/test/mocks/stdlib.sh
# the modules to be tested
# the modules to be tested
source
"
$(
pwd
)
"
/lib/uuid.sh
source
"
$(
pwd
)
"
/lib/environment.sh
source
"
$(
pwd
)
"
/lib/environment.sh
source
"
$(
pwd
)
"
/lib/json.sh
source
"
$(
pwd
)
"
/lib/json.sh
source
"
$(
pwd
)
"
/lib/json.sh
source
"
$(
pwd
)
"
/lib/json.sh
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment