sapling/tests/integration/test-lfs-import.t
Thomas Orozco 53bf2886cc mononoke: connect stdlog and slog
Summary:
This wires up the stdlog crate with our slog output. The upshot is that we can
now run binaries with `RUST_LOG` set and expect it to work.

This is nice because many crates use stdlog (e.g.  Tokio, Hyper), so this is
convenient to get access to their logging.  For example, if you run with
`RUST_LOG=gotham=info,hyper=debug`, then you get debug logs from Hyper and info
logs from Gotham.

The way this works is by registering a stdlog logger that uses the env_logger's
filter (the one that "invented" `RUST_LOG`) to filter logs, and routes them to
slog if they pass. Note that the slog Logger used there doesn't do any
filtering, since we already do it before sending logs there.

One thing to keep in mind is that we should only register the stdlog global
logger once. I've renamed `get_logger` to `init_logging` to make this clearer.
This behavior is similar to what we do with `init_cachelib`. I've updated
callsites accordingly.

Note that we explicitly tell the stdlog framework to ignore anything that we
won't consider for logging. If you don't set `RUST_LOG`, then the default
logging level is `Error`, which means that anything below error that is sent to
stdlog won't even get to out filtering logic (the stdlog macros for logging
check for the global level before actually logging), so this is cheap unless
you do set `RUST_LOG`.

As part of this, I've also updated all our binaries (and therefore, tests) to
use glog for logging. We had been meaning to do this, and it was convenient to
do it here because the other logger factory we were using didn't make it easy
to get a Drain without putting it a Logger.

Reviewed By: ahornby

Differential Revision: D17314200

fbshipit-source-id: 19b5e8edc3bbe7ba02ccec4f1852dc3587373fff
2019-09-12 04:13:11 -07:00

76 lines
4.4 KiB
Perl

$ . "${TEST_FIXTURES}/library.sh"
$ LFS_HELPER="$(realpath "${TESTTMP}/lfs")"
# Setup Mononoke
$ setup_mononoke_config
# Create a mock LFS helper
$ cat > "$LFS_HELPER" <<EOF
> #!/bin/bash
> echo "lfs: \$*" >&2
> yes 2>/dev/null | head -c 128
> EOF
$ chmod +x "$LFS_HELPER"
# Test importing blobs
$ cd "$TESTTMP"
$ cat > bad_hash << EOF
> version https://git-lfs.github.com/spec/v1
> oid sha256:d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38
> size 128
> EOF
$ lfs_import "$LFS_HELPER" "$(cat bad_hash)"
* using repo "repo" repoid RepositoryId(0) (glob)
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
Error: InvalidSha256(InvalidHash { expected: Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38), effective: Sha256(14217d6d598954662767fb151ff41cc10261f233d60d92aba9fdaa8534c2db33) })
[1]
$ cat > bad_size << EOF
> version https://git-lfs.github.com/spec/v1
> oid sha256:14217d6d598954662767fb151ff41cc10261f233d60d92aba9fdaa8534c2db33
> size 128
> EOF
$ lfs_import "$LFS_HELPER" "$(cat bad_hash)"
* using repo "repo" repoid RepositoryId(0) (glob)
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
* lfs_upload: importing blob Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38) (glob)
lfs: d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38 128
Error: InvalidSha256(InvalidHash { expected: Sha256(d6c9160e8ac378413dd55fba213970bbf55afdddaf85999dc3cf8d941f08fb38), effective: Sha256(14217d6d598954662767fb151ff41cc10261f233d60d92aba9fdaa8534c2db33) })
[1]
$ cat > ok << EOF
> version https://git-lfs.github.com/spec/v1
> oid sha256:14217d6d598954662767fb151ff41cc10261f233d60d92aba9fdaa8534c2db33
> size 128
> EOF
$ lfs_import "$LFS_HELPER" "$(cat ok)"
* using repo "repo" repoid RepositoryId(0) (glob)
* lfs_upload: importing blob Sha256(14217d6d598954662767fb151ff41cc10261f233d60d92aba9fdaa8534c2db33) (glob)
lfs: 14217d6d598954662767fb151ff41cc10261f233d60d92aba9fdaa8534c2db33 128
* lfs_upload: imported blob Sha256(14217d6d598954662767fb151ff41cc10261f233d60d92aba9fdaa8534c2db33) (glob)