#!/bin/bash
set -e
. tests/lib

t-restrict x-dgit-skip-suite,bullseye
t-restrict x-dgit-skip-suite,buster
t-dependencies T2U mpack

t-t2u-settings
t-debpolicy
export DGIT_TEST_MUNPACK=munpack

t-t2u-native-prep

t-t2u-setup-repo

tagname=test-dummy/$v

export DGIT_TEST_DEBUG=
export DGIT_TEST_DEBPUSH_DEBUG=
export DGIT_DRS_DEBUG=0
export DGIT_TEST_NDEBUG=

t-t2u-test
t-t2u-succeeded
t-pushed-good master

cd ..

cat <<'END' >sendmail.expected
    ???
    sendmail -oee -odb -oi -t -fnoreply@example.org
    From: test-dummy tag2upload service <noreply@example.org>
    Subject: [tag2upload fake-job] uploaded example 1.0-1
    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary=???
    Content-Transfer-Encoding: 8bit
    X-Debian-Tag2upload-Distro: test-dummy
    X-Debian-Tag2upload-JobId: fake-job
    X-Debian-Tag2upload-Url: ???/fake_https_dir/gitlab.test-dummy.example.org/example.git
    X-Debian-Tag2upload-Status: uploaded
    X-Debian-Tag2upload-Package: example
    To: dgit test git user <dgit-test@debian.example.net>
    CC: copies@example.org, spqr@example.com

    --???
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: 8bit
    Content-Disposition: inline

    job id: fake-job
    url: ???/fake_https_dir/gitlab.test-dummy.example.org/example.git
    tag: test-dummy/1.0-1
    preparing
    tag signature verified
    tag parsed ok
    source: example
    version: 1.0-1
    tag signer authorised for package
    source code fetched
    changelog parsed ok
    target: test-dummy unstable
    package is new in this suite
    no upstream tag/commit specified, not considering orig(s)
    processing successful
    Uploaded to unstable

    --???
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: 8bit
    Content-Disposition: attachment; filename="t2u_fake-job_tag.txt"
    Content-Description: input git tag

    object f68f0a55d4bba3833727b96b135ee8b66a049a77
    type commit
    tag test-dummy/1.0-1
    tagger dgit test git user <dgit-test@debian.example.net> 1530000000 +0100

    example release 1.0-1 for unstable

    [dgit distro=test-dummy split]
    [dgit please-upload source=example version=1.0-1]
    -----BEGIN PGP SIGNATURE-----

 +  ???
    -----END PGP SIGNATURE-----

    --???
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: 8bit
    Content-Disposition: attachment; filename="t2u_fake-job_log.txt"
    Content-Description: processing log

    # builder: oracle$ ???/t2u-ssh-for-t2u-oracled somehost env ...

    builder:work$ git fetch origin refs/tags/test-dummy/1.0-1:refs/tags/test-dummy/1.0-1
    From ???/fake_https_dir/gitlab.test-dummy.example.org/example
     * [new tag]         test-dummy/1.0-1 -> test-dummy/1.0-1
    # [ok]

    builder:work$ git checkout -q refs/tags/test-dummy/1.0-1
    # [ok]
    # source code fetched
    # changelog parsed ok
    # target: test-dummy unstable

    builder:work$ ???/dgit -wn -pexample --build-products-dir=../bpd --for-push fetch unstable
    canonical suite name for unstable is sid
    no version available from the archive
    dgit: source package example does not exist in suite unstable
    # [new]
    # package is new in this suite
    # no upstream tag/commit specified, not considering orig(s)

    oracle$ ???/dgit -wn -pexample --build-products-dir=../bpd --force-uploading-source-only --ssh=???/t2u-ssh-for-t2u-oracled --ssh:-oBatchMode=yes --dgit=env --dgit:???/dgit --package=example --expect-suite=unstable --expect-version=1.0-1 --tag2upload-builder-mode --split-view=always --new --trust-changelog '--dsc-control-add=Git-Tag-Tagger=dgit test git user <dgit-test@debian.example.net>' '--dsc-control-add=Git-Tag-Info=tag=??? fp=bcd22cd83243b79d3dfac33ea3dbcbc039b13d8a' '--ch-control-add=Git-Tag-Tagger=dgit test git user <dgit-test@debian.example.net>' '--ch-control-add=Git-Tag-Info=tag=??? fp=bcd22cd83243b79d3dfac33ea3dbcbc039b13d8a' rpush-source somehost:???/work

    canonical suite name for unstable is sid
##  Don't insist on particular output from dgit rpush.
 *  ???
    dgit (build host) ok: pushed and uploaded 1.0-1
    # [ok]
    # processing successful
    # Uploaded to unstable

    --???--
END

$troot/template-match-check sendmail.expected sendmail.last

t-ok
