github.com/replicatedcom/ship@v0.50.0/pkg/specs/gogetter/go_getter_test.go (about) 1 package gogetter 2 3 import ( 4 "testing" 5 ) 6 7 func TestIsGoGettable(t *testing.T) { 8 tests := []struct { 9 name string 10 path string 11 want bool 12 }{ 13 { 14 name: "empty", 15 path: "", 16 want: false, 17 }, 18 { 19 name: "helm chart", 20 path: "stable/mysql", 21 want: false, 22 }, 23 { 24 name: "github", 25 path: "github.com/replicatedhq/ship", 26 want: true, 27 }, 28 // { 29 // name: "bitbucket", 30 // // this needs to be a valid bitbucket repo to work 31 // path: "bitbucket.org/hashicorp/tf-test-git", 32 // want: true, 33 // }, 34 // { 35 // name: "bitbucket", 36 // // this needs to be a valid bitbucket repo to work 37 // path: "bitbucket.org/hashicorp/tf-test-hg", 38 // want: true, 39 // }, 40 } 41 for _, tt := range tests { 42 t.Run(tt.name, func(t *testing.T) { 43 if got := IsGoGettable(tt.path); got != tt.want { 44 t.Errorf("isGoGettable(%s) = %v, want %v", tt.path, got, tt.want) 45 } 46 }) 47 } 48 } 49 50 func TestUntreeGithub(t *testing.T) { 51 tests := []struct { 52 name string 53 path string 54 want string 55 subdir string 56 blob bool 57 }{ 58 { 59 name: "empty", 60 path: "", 61 want: "", 62 }, 63 { 64 name: "helm chart", 65 path: "stable/mysql", 66 want: "stable/mysql", 67 }, 68 { 69 name: "random nonsense", 70 path: "a string of random nonsense", 71 want: "a string of random nonsense", 72 }, 73 { 74 name: "bitbucket repo", 75 path: "bitbucket.org/ww/goautoneg", 76 want: "bitbucket.org/ww/goautoneg", 77 }, 78 { 79 name: "already configured go-getter string", 80 path: "github.com/replicatedhq/ship?ref=master//pkg/specs", 81 want: "github.com/replicatedhq/ship?ref=master//pkg/specs", 82 }, 83 { 84 name: "mocked github url with tree", 85 path: "github.com/OWNER/REPO/tree/REF/SUBDIR", 86 want: "github.com/OWNER/REPO?ref=REF//", 87 subdir: "SUBDIR", 88 }, 89 { 90 name: "ship repo in pkg dir on master", 91 path: "https://github.com/replicatedhq/ship/tree/master/pkg", 92 want: "github.com/replicatedhq/ship?ref=master//", 93 subdir: "pkg", 94 }, 95 { 96 name: "ship repo in pkg/specs dir on master", 97 path: "https://github.com/replicatedhq/ship/tree/master/pkg/specs", 98 want: "github.com/replicatedhq/ship?ref=master//", 99 subdir: "pkg/specs", 100 }, 101 { 102 name: "ship repo in pkg/specs dir at hash with www", 103 path: "https://www.github.com/replicatedhq/ship/tree/atestsha/pkg/specs", 104 want: "github.com/replicatedhq/ship?ref=atestsha//", 105 subdir: "pkg/specs", 106 }, 107 { 108 name: "ship repo in root dir on master with www", 109 path: "https://www.github.com/replicatedhq/ship/tree/master", 110 want: "github.com/replicatedhq/ship?ref=master//", 111 }, 112 { 113 name: "github repo with no tree", 114 path: "https://github.com/replicatedhq/ship", 115 want: "github.com/replicatedhq/ship?ref=master//", 116 }, 117 { 118 name: "github repo with no tree with www", 119 path: "https://www.github.com/replicatedhq/ship", 120 want: "github.com/replicatedhq/ship?ref=master//", 121 }, 122 { 123 name: "github repo with no tree with subdir", 124 path: "https://github.com/replicatedhq/ship/pkg/specs", 125 want: "github.com/replicatedhq/ship?ref=master//", 126 subdir: "pkg/specs", 127 }, 128 { 129 name: "github repo with no https or tree with subdir", 130 path: "github.com/replicatedhq/ship/pkg/specs", 131 want: "github.com/replicatedhq/ship?ref=master//", 132 subdir: "pkg/specs", 133 }, 134 { 135 name: "ship repo in pkg/specs dir at hash with www", 136 path: "https://www.github.com/replicatedhq/ship/blob/atestsha/pkg/specs/chart.go", 137 want: "github.com/replicatedhq/ship?ref=atestsha//", 138 subdir: "pkg/specs/chart.go", 139 blob: true, 140 }, 141 } 142 for _, tt := range tests { 143 t.Run(tt.name, func(t *testing.T) { 144 if got, subdir, blob := UntreeGithub(tt.path); got != tt.want || subdir != tt.subdir || blob != tt.blob { 145 t.Errorf("untreeGithub(%s) = %v, %v, %t want %v, %v, %t", tt.path, got, subdir, blob, tt.want, tt.subdir, tt.blob) 146 } 147 }) 148 } 149 }