github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/deployment/internal/repodiscovery/remote_test.go (about)

     1  package repodiscovery
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  type remoteCase struct {
     8  	in     string
     9  	out    string
    10  	hasErr bool
    11  }
    12  
    13  var cases = []remoteCase{
    14  	remoteCase{
    15  		in:  "http://github.com/example/hello.git",
    16  		out: "http://github.com/example/hello",
    17  	},
    18  	remoteCase{
    19  		in:  "https://github.com/example/hello.git",
    20  		out: "https://github.com/example/hello",
    21  	},
    22  	remoteCase{
    23  		in:  "https://github.com/example/hello",
    24  		out: "https://github.com/example/hello",
    25  	},
    26  	remoteCase{
    27  		in:  "git@github.com:example/hello.git",
    28  		out: "https://github.com/example/hello",
    29  	},
    30  	remoteCase{
    31  		in:  "git://github.com/example/hello.git",
    32  		out: "https://github.com/example/hello",
    33  	},
    34  	remoteCase{
    35  		in:  "ssh://git@github.com:example/hello.git",
    36  		out: "https://github.com/example/hello",
    37  	},
    38  	remoteCase{
    39  		in:  "git@github.com:example/hello.example.git",
    40  		out: "https://github.com/example/hello.example",
    41  	},
    42  	remoteCase{
    43  		in:  "https://github.com/example/hello.example",
    44  		out: "https://github.com/example/hello.example",
    45  	},
    46  	remoteCase{
    47  		in:  "https://username:password@github.com/example/hello.example",
    48  		out: "https://github.com/example/hello.example",
    49  	},
    50  	remoteCase{
    51  		in:  "git+ssh://git@github.com:example/hello.git",
    52  		out: "https://github.com/example/hello",
    53  	},
    54  	remoteCase{
    55  		in:  "git+https://isaacs@github.com/example/hello.git",
    56  		out: "https://github.com/example/hello",
    57  	},
    58  	remoteCase{
    59  		in:  "git+ssh://git@github.com:example/example.git",
    60  		out: "https://github.com/example/example",
    61  	},
    62  	remoteCase{
    63  		in:  "https://user@bitbucket.org/example/hello.git",
    64  		out: "https://bitbucket.org/example/hello",
    65  	},
    66  	remoteCase{
    67  		in:  "https://user:password@bitbucket.org/example/hello",
    68  		out: "https://bitbucket.org/example/hello",
    69  	},
    70  	remoteCase{
    71  		in:  "https://user@bitbucket.org/example/hello",
    72  		out: "https://bitbucket.org/example/hello",
    73  	},
    74  	remoteCase{
    75  		in:  "git@bitbucket.org:example/hello.git",
    76  		out: "https://bitbucket.org/example/hello",
    77  	},
    78  	remoteCase{
    79  		in:  "https://gitlab.com/gitlab-org/gitlab-ce.git",
    80  		out: "https://gitlab.com/gitlab-org/gitlab-ce",
    81  	},
    82  	remoteCase{
    83  		in:  "git@gitlab.com:gitlab-org/gitlab-ce.git",
    84  		out: "https://gitlab.com/gitlab-org/gitlab-ce",
    85  	},
    86  	remoteCase{
    87  		in:     "git@gitlab.com:%gitlab-org/gitlab-ce.git",
    88  		hasErr: true,
    89  	},
    90  	remoteCase{
    91  		in:     "",
    92  		hasErr: true,
    93  	},
    94  	remoteCase{
    95  		in:     "/path/repo",
    96  		hasErr: true,
    97  	},
    98  }
    99  
   100  func TestExtractRepoURL(t *testing.T) {
   101  	for _, c := range cases {
   102  		var got, err = ExtractRepoURL(c.in)
   103  
   104  		if got != c.out || (err != nil) == !c.hasErr {
   105  			t.Errorf("Expected ExtractRepoURL(%v) = (%v, has error = %v) got (%v, %v) instead instead", c.in, c.out, c.hasErr, got, err)
   106  		}
   107  	}
   108  }