|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load 'util/init.sh' |
| 4 | + |
| 5 | + |
| 6 | +@test "fails on no arguments" { |
| 7 | + run util.construct_clone_url |
| 8 | + |
| 9 | + assert_failure |
| 10 | + assert_line -p "Must supply a repository" |
| 11 | +} |
| 12 | + |
| 13 | +@test "parses with full https url" { |
| 14 | + util.construct_clone_url 'https://gitlab.com/eankeen/proj' |
| 15 | + |
| 16 | + assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ] |
| 17 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 18 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 19 | + assert [ "$REPLY4" = '' ] |
| 20 | +} |
| 21 | + |
| 22 | +@test "parses with full http url" { |
| 23 | + util.construct_clone_url 'http://gitlab.com/eankeen/proj' |
| 24 | + |
| 25 | + assert [ "$REPLY1" = 'http://gitlab.com/eankeen/proj.git' ] |
| 26 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 27 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 28 | + assert [ "$REPLY4" = '' ] |
| 29 | +} |
| 30 | + |
| 31 | +@test "parses with full https url with .git ending" { |
| 32 | + util.construct_clone_url 'https://gitlab.com/eankeen/proj' |
| 33 | + |
| 34 | + assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ] |
| 35 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 36 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 37 | + assert [ "$REPLY4" = '' ] |
| 38 | +} |
| 39 | + |
| 40 | +@test "parses with full http url with .git ending" { |
| 41 | + util.construct_clone_url 'http://gitlab.com/eankeen/proj.git' |
| 42 | + |
| 43 | + assert [ "$REPLY1" = 'http://gitlab.com/eankeen/proj.git' ] |
| 44 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 45 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 46 | + assert [ "$REPLY4" = '' ] |
| 47 | +} |
| 48 | + |
| 49 | +@test "parses with full ssh url" { |
| 50 | + util.construct_clone_url 'git@gitlab.com:eankeen/proj.git' |
| 51 | + |
| 52 | + assert [ "$REPLY1" = 'git@gitlab.com:eankeen/proj' ] |
| 53 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 54 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 55 | + assert [ "$REPLY4" = '' ] |
| 56 | +} |
| 57 | + |
| 58 | +@test "parses with package and domain" { |
| 59 | + util.construct_clone_url 'gitlab.com/eankeen/proj' |
| 60 | + |
| 61 | + assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ] |
| 62 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 63 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 64 | + assert [ "$REPLY4" = '' ] |
| 65 | +} |
| 66 | + |
| 67 | +@test "parses with package and domain and ref" { |
| 68 | + util.construct_clone_url 'gitlab.com/eankeen/proj@v0.1.0' |
| 69 | + |
| 70 | + assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ] |
| 71 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 72 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 73 | + assert [ "$REPLY4" = 'v0.1.0' ] |
| 74 | +} |
| 75 | + |
| 76 | +@test "parses with package and domain with ssh" { |
| 77 | + util.construct_clone_url 'gitlab.com/eankeen/proj' 'yes' |
| 78 | + |
| 79 | + assert [ "$REPLY1" = 'git@gitlab.com:eankeen/proj' ] |
| 80 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 81 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 82 | + assert [ "$REPLY4" = '' ] |
| 83 | +} |
| 84 | + |
| 85 | +@test "parses with package and domain and ref with ssh" { |
| 86 | + util.construct_clone_url 'gitlab.com/eankeen/proj@v0.1.0' 'yes' |
| 87 | + |
| 88 | + assert [ "$REPLY1" = 'git@gitlab.com:eankeen/proj' ] |
| 89 | + assert [ "$REPLY2" = 'gitlab.com' ] |
| 90 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 91 | + assert [ "$REPLY4" = 'v0.1.0' ] |
| 92 | +} |
| 93 | + |
| 94 | +@test "parses with package" { |
| 95 | + util.construct_clone_url 'eankeen/proj' |
| 96 | + |
| 97 | + assert [ "$REPLY1" = 'https://github.com/eankeen/proj.git' ] |
| 98 | + assert [ "$REPLY2" = 'github.com' ] |
| 99 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 100 | + assert [ "$REPLY4" = '' ] |
| 101 | +} |
| 102 | + |
| 103 | +@test "parses with package and ref" { |
| 104 | + util.construct_clone_url 'eankeen/proj@v0.2.0' |
| 105 | + |
| 106 | + assert [ "$REPLY1" = 'https://github.com/eankeen/proj.git' ] |
| 107 | + assert [ "$REPLY2" = 'github.com' ] |
| 108 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 109 | + assert [ "$REPLY4" = 'v0.2.0' ] |
| 110 | +} |
| 111 | + |
| 112 | +@test "parses with package with ssh" { |
| 113 | + util.construct_clone_url 'eankeen/proj' 'yes' |
| 114 | + |
| 115 | + assert [ "$REPLY1" = 'git@github.com:eankeen/proj' ] |
| 116 | + assert [ "$REPLY2" = 'github.com' ] |
| 117 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 118 | + assert [ "$REPLY4" = '' ] |
| 119 | +} |
| 120 | + |
| 121 | +@test "parses with package with ssh and ref" { |
| 122 | + util.construct_clone_url 'eankeen/proj@v0.2.0' 'yes' |
| 123 | + |
| 124 | + assert [ "$REPLY1" = 'git@github.com:eankeen/proj' ] |
| 125 | + assert [ "$REPLY2" = 'github.com' ] |
| 126 | + assert [ "$REPLY3" = 'eankeen/proj' ] |
| 127 | + assert [ "$REPLY4" = 'v0.2.0' ] |
| 128 | +} |
0 commit comments