Files
audio-library-manager/test/flac2opus-manager-test.rkt
T
2026-06-10 08:45:11 +02:00

62 lines
2.4 KiB
Racket

#lang racket/base
(require rackunit
racket/file
racket/path
"../flac2opus-manager.rkt")
(define tmp (make-temporary-file "alm-flac2opus-src-~a" 'directory))
(define out (make-temporary-file "alm-flac2opus-out-~a" 'directory))
(define sub (build-path tmp "disc1"))
(make-directory* sub)
(call-with-output-file (build-path tmp ".flac-48khz-manager.ini") #:exists 'replace
(lambda (o)
(display "[manager]\n" o)
(display "change-detection=quick\n" o)
(display "display-log=false\n" o)
(display "dry-run=false\n" o)
(display "log-file=.flac-48khz-manager.log\n" o)
(display "[mail]\n" o)
(display "enabled=false\n" o)))
(define flac (build-path sub "track.flac"))
(define pdf (build-path sub "booklet.pdf"))
(define jpg (build-path tmp "cover.jpg"))
(call-with-output-file flac #:exists 'replace (lambda (o) (display "fake flac" o)))
(call-with-output-file pdf #:exists 'replace (lambda (o) (display "booklet" o)))
(call-with-output-file jpg #:exists 'replace (lambda (o) (display "jpg" o)))
(define convert-count 0)
(define (mock-convert src dst kbps)
(set! convert-count (add1 convert-count))
(make-directory* (let-values ([(base name dir?) (split-path dst)]) base))
(call-with-output-file dst #:exists 'replace
(lambda (o) (fprintf o "opus from ~a at ~a" (path->string src) kbps)))
(lambda () kbps))
(define first-summary
(manage-flac2opus-tree tmp out #:kbps 192 #:convert-proc mock-convert))
(check-equal? (assoc 'seen first-summary) '(seen . 3))
(check-equal? (assoc 'converted first-summary) '(converted . 1))
(check-equal? (assoc 'copied first-summary) '(copied . 2))
(check-true (file-exists? (build-path out "disc1" "track.opus")))
(check-true (file-exists? (build-path out "disc1" "booklet.pdf")))
(check-true (file-exists? (build-path out "cover.jpg")))
(check-equal? convert-count 1)
(define second-summary
(manage-flac2opus-tree tmp out #:kbps 192 #:convert-proc mock-convert))
(check-equal? (assoc 'seen second-summary) '(seen . 3))
(check-equal? (assoc 'unchanged second-summary) '(unchanged . 3))
(check-equal? convert-count 1)
(delete-file pdf)
(define third-summary
(manage-flac2opus-tree tmp out #:kbps 192 #:convert-proc mock-convert))
(check-equal? (assoc 'removed third-summary) '(removed . 1))
(check-false (file-exists? (build-path out "disc1" "booklet.pdf")))
(delete-directory/files tmp)
(delete-directory/files out)