Refactor random generation into a definition to make it reusable
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
@@ -7,10 +7,12 @@ import (
|
||||
)
|
||||
|
||||
TestNetlify: {
|
||||
random: #Random & {}
|
||||
|
||||
// Generate a website containing the random number
|
||||
html: #up: [
|
||||
op.#WriteFile & {
|
||||
content: random
|
||||
content: random.out
|
||||
dest: "index.html"
|
||||
},
|
||||
]
|
||||
@@ -38,7 +40,7 @@ TestNetlify: {
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
test "$(curl \#(deploy.deployUrl))" = "\#(random)"
|
||||
test "$(curl \#(deploy.deployUrl))" = "\#(random.out)"
|
||||
"""#,
|
||||
]
|
||||
},
|
||||
|
@@ -1,20 +1,33 @@
|
||||
package netlify
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"dagger.io/alpine"
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
// Generate a random number
|
||||
random: {
|
||||
string
|
||||
#up: [
|
||||
op.#Load & {from: alpine.#Image},
|
||||
op.#Exec & {
|
||||
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"]
|
||||
},
|
||||
op.#Export & {
|
||||
source: "/rand"
|
||||
},
|
||||
]
|
||||
#Random: {
|
||||
size: *12 | number
|
||||
|
||||
out: {
|
||||
string
|
||||
|
||||
#up: [
|
||||
op.#Load & {from: alpine.#Image},
|
||||
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: ["sh", "-c", #"""
|
||||
tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
|
||||
"""#,
|
||||
]
|
||||
env: SIZE: strconv.FormatInt(size, 10)
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/rand"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user