github.com/whyrusleeping/gx@v0.14.3/tests/t0030-import.sh (about)

     1  #!/bin/sh
     2  #
     3  # Copyright (c) 2015 Jeromy Johnson
     4  # MIT Licensed; see the LICENSE file in this repository.
     5  #
     6  
     7  test_description="test package importing"
     8  
     9  . lib/test-lib.sh
    10  
    11  check_package_import() {
    12  	pkg=$1
    13  	imphash=$2
    14  	name=$3
    15  
    16  	test_expect_success "dir was created" '
    17  		stat $pkg/vendor/gx/ipfs/$imphash > /dev/null
    18  	'
    19  
    20  	test_expect_success "dep set in package.json" '
    21  		jq -r ".gxDependencies[] | select(.hash == \"$imphash\") | .name" $pkg/package.json > name
    22  	'
    23  
    24  	test_expect_success "name looks good" '
    25  		echo "$name" > exp_name &&
    26  		test_cmp exp_name name
    27  	'
    28  }
    29  
    30  test_init_ipfs
    31  test_launch_ipfs_daemon
    32  
    33  test_expect_success "setup test packages" '
    34  	make_package a none
    35  	make_package b none
    36  	make_package c none
    37  	make_package d none
    38  '
    39  
    40  test_expect_success "publish the packages a and b" '
    41  	pkgA=$(publish_package a) &&
    42  	pkgB=$(publish_package b)
    43  '
    44  
    45  test_expect_success "import package a succeeds" '
    46  	pkg_run c gx import $pkgA
    47  '
    48  
    49  check_package_import c $pkgA a
    50  
    51  test_expect_success "import package b succeeds" '
    52  	pkg_run c gx import $pkgB
    53  '
    54  
    55  check_package_import c $pkgB b
    56  
    57  test_expect_success "publish c succeeds" '
    58  	pkgC=$(publish_package c)
    59  '
    60  
    61  test_expect_success "d imports c succeeds" '
    62  	pkg_run d gx import $pkgC
    63  '
    64  
    65  check_package_import d $pkgC c
    66  
    67  test_expect_success "importing c brought along a and b" '
    68  	stat d/vendor/gx/ipfs/$pkgA/a/package.json > /dev/null &&
    69  	stat d/vendor/gx/ipfs/$pkgB/b/package.json > /dev/null
    70  '
    71  
    72  test_expect_success "install d works" '
    73  	pkg_run d gx --verbose install --nofancy > install_out
    74  '
    75  
    76  # Example output: `[done] [install] 0s    Qmemb8MUvUJC1VRDh8NrpovYJCEGXFfyXGbxccabXXY8G9 b`,
    77  # match elapsed time with `[0-9]\+\(.[0-9]\+\)\?[a-z]\+\s\+`.
    78  test_expect_success "install output looks good" '
    79  	grep "\[get \] \[install\] \s\+$pkgA a" install_out &&
    80  	grep "\[get \] \[install\] \s\+$pkgB b" install_out &&
    81  	grep "\[get \] \[install\] \s\+$pkgC c" install_out &&
    82  	grep "\[done\] \[install\] [0-9]\+\(.[0-9]\+\)\?[a-z]\+\s\+$pkgA a" install_out &&
    83  	grep "\[done\] \[install\] [0-9]\+\(.[0-9]\+\)\?[a-z]\+\s\+$pkgB b" install_out &&
    84  	grep "\[done\] \[install\] [0-9]\+\(.[0-9]\+\)\?[a-z]\+\s\+$pkgC c" install_out
    85  '
    86  
    87  test_expect_success "deps look correct" '
    88  	pkg_run d gx deps --tree > deps_out
    89  '
    90  
    91  test_expect_success "deps tree looks right" '
    92  	printf "└─ \033[1mc\033[0m    %s 0.0.0\n" "$pkgC" > deps_exp &&
    93  	printf "   ├─ \033[1ma\033[0m %s 0.0.0\n" "$pkgA" >> deps_exp &&
    94  	printf "   └─ \033[1mb\033[0m %s 0.0.0\n" "$pkgB" >> deps_exp &&
    95  	test_cmp deps_exp deps_out
    96  '
    97  
    98  test_kill_ipfs_daemon
    99  
   100  test_done