diff options
| -rw-r--r-- | .dir-locals.el | 1 | ||||
| -rw-r--r-- | guix/tests/git.scm | 67 | ||||
| -rw-r--r-- | tests/builders.scm | 8 | ||||
| -rw-r--r-- | tests/derivations.scm | 55 |
4 files changed, 107 insertions, 24 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index 022a338217e..4bd0d97cb33 100644 --- a/.dir-locals.el +++ b/.dir-locals.el | |||
| @@ -202,6 +202,7 @@ | |||
| 202 | (eval . (put 'call-with-progress-reporter 'scheme-indent-function 1)) | 202 | (eval . (put 'call-with-progress-reporter 'scheme-indent-function 1)) |
| 203 | (eval . (put 'with-repository 'scheme-indent-function 2)) | 203 | (eval . (put 'with-repository 'scheme-indent-function 2)) |
| 204 | (eval . (put 'with-temporary-git-repository 'scheme-indent-function 2)) | 204 | (eval . (put 'with-temporary-git-repository 'scheme-indent-function 2)) |
| 205 | (eval . (put 'with-served-git-repository 'scheme-indent-function 2)) | ||
| 205 | (eval . (put 'with-environment-variables 'scheme-indent-function 1)) | 206 | (eval . (put 'with-environment-variables 'scheme-indent-function 1)) |
| 206 | (eval . (put 'with-fresh-gnupg-setup 'scheme-indent-function 1)) | 207 | (eval . (put 'with-fresh-gnupg-setup 'scheme-indent-function 1)) |
| 207 | 208 | ||
diff --git a/guix/tests/git.scm b/guix/tests/git.scm index d51e49e5148..a649c1fa6e8 100644 --- a/guix/tests/git.scm +++ b/guix/tests/git.scm | |||
| @@ -27,6 +27,9 @@ | |||
| 27 | #:export (git-command | 27 | #:export (git-command |
| 28 | with-temporary-git-repository | 28 | with-temporary-git-repository |
| 29 | with-git-repository | 29 | with-git-repository |
| 30 | serve-git-repository | ||
| 31 | with-served-git-repository | ||
| 32 | with-served-temporary-git-repository | ||
| 30 | find-commit)) | 33 | find-commit)) |
| 31 | 34 | ||
| 32 | (define git-command | 35 | (define git-command |
| @@ -151,3 +154,67 @@ per DIRECTIVES." | |||
| 151 | #f | 154 | #f |
| 152 | repository) | 155 | repository) |
| 153 | (error "commit not found" message))) | 156 | (error "commit not found" message))) |
| 157 | |||
| 158 | (define* (serve-git-repository directory #:optional port) | ||
| 159 | "Run \"git daemon\" to serve the bare git repository at DIRECTORY as the | ||
| 160 | root resource on PORT on the loopback interface. If PORT isn't provided or is | ||
| 161 | #f, select an arbitrary unused port instead. | ||
| 162 | |||
| 163 | Return two values: the PID of the newly-spawned process and the port it is | ||
| 164 | listening on." | ||
| 165 | (let ((port (or port | ||
| 166 | ;; XXX: race between when it's closed and 'git daemon' binds | ||
| 167 | ;; the same port. | ||
| 168 | (call-with-port (socket AF_INET SOCK_STREAM 0) | ||
| 169 | (lambda (sock) | ||
| 170 | (bind sock AF_INET INADDR_LOOPBACK 0) | ||
| 171 | (sockaddr:port (getsockname sock))))))) | ||
| 172 | (values | ||
| 173 | (spawn (git-command) | ||
| 174 | (list (basename (git-command)) | ||
| 175 | "daemon" | ||
| 176 | (string-append "--base-path=" directory) | ||
| 177 | "--listen=127.0.0.1" | ||
| 178 | "--listen=::1" | ||
| 179 | (string-append "--port=" (number->string port)) | ||
| 180 | "--export-all" ;; don't require git-daemon-export-ok file | ||
| 181 | "--strict-paths" | ||
| 182 | "--" | ||
| 183 | ;; with --strict-paths this limits requests to exactly this | ||
| 184 | ;; directory. The client can't fetch an empty string, | ||
| 185 | ;; though (has to be at least "/"), so add a trailing slash. | ||
| 186 | (if (string-suffix? "/" directory) | ||
| 187 | directory | ||
| 188 | (string-append directory "/")))) | ||
| 189 | port))) | ||
| 190 | |||
| 191 | (define* (call-with-served-git-repository directory proc #:key port) | ||
| 192 | "Serve DIRECTORY as the root resource \"/\" on the loopback interface during | ||
| 193 | the dynamic extent of a single invocation of PROC. PROC is called with a | ||
| 194 | single integer argument indicating which port of the loopback interface \"git | ||
| 195 | daemon\" is listening on. If PORT is specified, that port will be used, | ||
| 196 | otherwise a random unused port will be chosen." | ||
| 197 | (call-with-values (lambda () | ||
| 198 | (serve-git-repository directory port)) | ||
| 199 | (lambda (pid port) | ||
| 200 | (dynamic-wind | ||
| 201 | (const #t) | ||
| 202 | (lambda () | ||
| 203 | (proc port)) | ||
| 204 | (lambda () | ||
| 205 | (kill pid SIGTERM) | ||
| 206 | (waitpid pid)))))) | ||
| 207 | |||
| 208 | (define-syntax-rule (with-served-git-repository directory port exp ...) | ||
| 209 | "Evaluate EXP in a context where the identifier PORT is bound to a port | ||
| 210 | number on which \"git daemon\" is serving DIRECTORY as the root resource | ||
| 211 | \"/\"." | ||
| 212 | (call-with-served-git-repository directory | ||
| 213 | (lambda (port) | ||
| 214 | exp ...))) | ||
| 215 | |||
| 216 | (define-syntax-rule (with-served-temporary-git-repository directory port | ||
| 217 | directives exp ...) | ||
| 218 | (with-temporary-git-repository directory directives | ||
| 219 | (with-served-git-repository (string-append directory "/.git") port | ||
| 220 | exp ...))) | ||
diff --git a/tests/builders.scm b/tests/builders.scm index 0ed295a93f4..44add1d13ea 100644 --- a/tests/builders.scm +++ b/tests/builders.scm | |||
| @@ -88,10 +88,10 @@ | |||
| 88 | (and (file-exists? out) | 88 | (and (file-exists? out) |
| 89 | (valid-path? %store out)))) | 89 | (valid-path? %store out)))) |
| 90 | 90 | ||
| 91 | (test-equal "git-fetch, file URI" | 91 | (test-equal "git-fetch, local URI" |
| 92 | '("." ".." "a.txt" "b.scm") | 92 | '("." ".." "a.txt" "b.scm") |
| 93 | (let ((nonce (random-text))) | 93 | (let ((nonce (random-text))) |
| 94 | (with-temporary-git-repository directory | 94 | (with-served-temporary-git-repository directory port |
| 95 | `((add "a.txt" ,nonce) | 95 | `((add "a.txt" ,nonce) |
| 96 | (add "b.scm" "#t") | 96 | (add "b.scm" "#t") |
| 97 | (commit "Commit.") | 97 | (commit "Commit.") |
| @@ -103,7 +103,9 @@ | |||
| 103 | #:recursive? #t)) | 103 | #:recursive? #t)) |
| 104 | (drv (git-fetch | 104 | (drv (git-fetch |
| 105 | (git-reference | 105 | (git-reference |
| 106 | (url (string-append "file://" directory)) | 106 | (url (string-append "git://localhost:" |
| 107 | (number->string port) | ||
| 108 | "/")) | ||
| 107 | (commit "v1.0.0")) | 109 | (commit "v1.0.0")) |
| 108 | 'sha256 hash | 110 | 'sha256 hash |
| 109 | "git-fetch-test"))) | 111 | "git-fetch-test"))) |
diff --git a/tests/derivations.scm b/tests/derivations.scm index 077aee09094..d4cca0f6058 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm | |||
| @@ -306,12 +306,14 @@ | |||
| 306 | get-string-all) | 306 | get-string-all) |
| 307 | text)))))) | 307 | text)))))) |
| 308 | 308 | ||
| 309 | (define %nonce (random-text)) | ||
| 310 | |||
| 309 | (test-equal "'git-download' built-in builder" | 311 | (test-equal "'git-download' built-in builder" |
| 310 | `(("/a.txt" . "AAA") | 312 | `(("/a.txt" . ,%nonce) |
| 311 | ("/b.scm" . "#t")) | 313 | ("/b.scm" . "#t")) |
| 312 | (let ((nonce (random-text))) | 314 | (let ((nonce (random-text))) |
| 313 | (with-temporary-git-repository directory | 315 | (with-served-temporary-git-repository directory port |
| 314 | `((add "a.txt" "AAA") | 316 | `((add "a.txt" ,%nonce) |
| 315 | (add "b.scm" "#t") | 317 | (add "b.scm" "#t") |
| 316 | (commit ,nonce)) | 318 | (commit ,nonce)) |
| 317 | (let* ((commit (with-repository directory repository | 319 | (let* ((commit (with-repository directory repository |
| @@ -322,7 +324,9 @@ | |||
| 322 | #:env-vars | 324 | #:env-vars |
| 323 | `(("url" | 325 | `(("url" |
| 324 | . ,(object->string | 326 | . ,(object->string |
| 325 | (string-append "file://" directory))) | 327 | (string-append "git://localhost:" |
| 328 | (number->string port) | ||
| 329 | "/"))) | ||
| 326 | ("commit" . ,commit)) | 330 | ("commit" . ,commit)) |
| 327 | #:hash-algo 'sha256 | 331 | #:hash-algo 'sha256 |
| 328 | #:hash (file-hash* directory | 332 | #:hash (file-hash* directory |
| @@ -335,7 +339,7 @@ | |||
| 335 | (directory-contents (derivation->output-path drv) get-string-all))))) | 339 | (directory-contents (derivation->output-path drv) get-string-all))))) |
| 336 | 340 | ||
| 337 | (test-assert "'git-download' built-in builder, invalid hash" | 341 | (test-assert "'git-download' built-in builder, invalid hash" |
| 338 | (with-temporary-git-repository directory | 342 | (with-served-temporary-git-repository directory port |
| 339 | `((add "a.txt" "AAA") | 343 | `((add "a.txt" "AAA") |
| 340 | (add "b.scm" "#t") | 344 | (add "b.scm" "#t") |
| 341 | (commit "Commit!")) | 345 | (commit "Commit!")) |
| @@ -347,7 +351,9 @@ | |||
| 347 | #:env-vars | 351 | #:env-vars |
| 348 | `(("url" | 352 | `(("url" |
| 349 | . ,(object->string | 353 | . ,(object->string |
| 350 | (string-append "file://" directory))) | 354 | (string-append "git://localhost:" |
| 355 | (number->string port) | ||
| 356 | "/"))) | ||
| 351 | ("commit" . ,commit)) | 357 | ("commit" . ,commit)) |
| 352 | #:hash-algo 'sha256 | 358 | #:hash-algo 'sha256 |
| 353 | #:hash (gcrypt:sha256 #vu8()) | 359 | #:hash (gcrypt:sha256 #vu8()) |
| @@ -358,7 +364,7 @@ | |||
| 358 | #f)))) | 364 | #f)))) |
| 359 | 365 | ||
| 360 | (test-assert "'git-download' built-in builder, invalid commit" | 366 | (test-assert "'git-download' built-in builder, invalid commit" |
| 361 | (with-temporary-git-repository directory | 367 | (with-served-temporary-git-repository directory port |
| 362 | `((add "a.txt" "AAA") | 368 | `((add "a.txt" "AAA") |
| 363 | (add "b.scm" "#t") | 369 | (add "b.scm" "#t") |
| 364 | (commit "Commit!")) | 370 | (commit "Commit!")) |
| @@ -367,7 +373,9 @@ | |||
| 367 | #:env-vars | 373 | #:env-vars |
| 368 | `(("url" | 374 | `(("url" |
| 369 | . ,(object->string | 375 | . ,(object->string |
| 370 | (string-append "file://" directory))) | 376 | (string-append "git://localhost:" |
| 377 | (number->string port) | ||
| 378 | "/"))) | ||
| 371 | ("commit" | 379 | ("commit" |
| 372 | . "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 380 | . "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 373 | #:hash-algo 'sha256 | 381 | #:hash-algo 'sha256 |
| @@ -379,19 +387,24 @@ | |||
| 379 | #f)))) | 387 | #f)))) |
| 380 | 388 | ||
| 381 | (test-assert "'git-download' built-in builder, not found" | 389 | (test-assert "'git-download' built-in builder, not found" |
| 382 | (let* ((drv (derivation %store "git-download" | 390 | (with-served-temporary-git-repository directory port |
| 383 | "builtin:git-download" '() | 391 | '() |
| 384 | #:env-vars | 392 | (let* ((drv (derivation %store "git-download" |
| 385 | `(("url" . "file:///does-not-exist.git") | 393 | "builtin:git-download" '() |
| 386 | ("commit" | 394 | #:env-vars |
| 387 | . "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 395 | `(("url" . ,(object->string |
| 388 | #:hash-algo 'sha256 | 396 | (string-append "git://localhost:" |
| 389 | #:hash (gcrypt:sha256 #vu8()) | 397 | (number->string port) |
| 390 | #:recursive? #t))) | 398 | "/nonexistent"))) |
| 391 | (guard (c ((store-protocol-error? c) | 399 | ("commit" |
| 392 | (string-contains (store-protocol-error-message c) "failed"))) | 400 | . "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 393 | (build-derivations %store (list drv)) | 401 | #:hash-algo 'sha256 |
| 394 | #f))) | 402 | #:hash (gcrypt:sha256 #vu8()) |
| 403 | #:recursive? #t))) | ||
| 404 | (guard (c ((store-protocol-error? c) | ||
| 405 | (string-contains (store-protocol-error-message c) "failed"))) | ||
| 406 | (build-derivations %store (list drv)) | ||
| 407 | #f)))) | ||
| 395 | 408 | ||
| 396 | (test-equal "derivation-name" | 409 | (test-equal "derivation-name" |
| 397 | "foo-0.0" | 410 | "foo-0.0" |
