|
| 1 | +// |
| 2 | +// Copyright 2021, Sander van Harmelen |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | + |
| 17 | +package gitlab |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "net/http" |
| 22 | + "reflect" |
| 23 | + "testing" |
| 24 | +) |
| 25 | + |
| 26 | +func TestListTemplates(t *testing.T) { |
| 27 | + mux, server, client := setup(t) |
| 28 | + defer teardown(server) |
| 29 | + |
| 30 | + mux.HandleFunc("/api/v4/templates/gitignores", func(w http.ResponseWriter, r *http.Request) { |
| 31 | + testMethod(t, r, http.MethodGet) |
| 32 | + fmt.Fprintf(w, `[ |
| 33 | + { |
| 34 | + "content": "Actionscript", |
| 35 | + "name": "Actionscript" |
| 36 | + }, |
| 37 | + { |
| 38 | + "content": "Ada", |
| 39 | + "name": "Ada" |
| 40 | + }, |
| 41 | + { |
| 42 | + "content": "Agda", |
| 43 | + "name": "Agda" |
| 44 | + }, |
| 45 | + { |
| 46 | + "content": "Android", |
| 47 | + "name": "Android" |
| 48 | + }, |
| 49 | + { |
| 50 | + "content": "AppEngine", |
| 51 | + "name": "AppEngine" |
| 52 | + }, |
| 53 | + { |
| 54 | + "content": "AppceleratorTitanium", |
| 55 | + "name": "AppceleratorTitanium" |
| 56 | + }, |
| 57 | + { |
| 58 | + "content": "ArchLinuxPackages", |
| 59 | + "name": "ArchLinuxPackages" |
| 60 | + }, |
| 61 | + { |
| 62 | + "content": "Autotools", |
| 63 | + "name": "Autotools" |
| 64 | + }, |
| 65 | + { |
| 66 | + "content": "C", |
| 67 | + "name": "C" |
| 68 | + }, |
| 69 | + { |
| 70 | + "content": "C++", |
| 71 | + "name": "C++" |
| 72 | + }, |
| 73 | + { |
| 74 | + "content": "CFWheels", |
| 75 | + "name": "CFWheels" |
| 76 | + }, |
| 77 | + { |
| 78 | + "content": "CMake", |
| 79 | + "name": "CMake" |
| 80 | + }, |
| 81 | + { |
| 82 | + "content": "CUDA", |
| 83 | + "name": "CUDA" |
| 84 | + }, |
| 85 | + { |
| 86 | + "content": "CakePHP", |
| 87 | + "name": "CakePHP" |
| 88 | + }, |
| 89 | + { |
| 90 | + "content": "ChefCookbook", |
| 91 | + "name": "ChefCookbook" |
| 92 | + }, |
| 93 | + { |
| 94 | + "content": "Clojure", |
| 95 | + "name": "Clojure" |
| 96 | + }, |
| 97 | + { |
| 98 | + "content": "CodeIgniter", |
| 99 | + "name": "CodeIgniter" |
| 100 | + }, |
| 101 | + { |
| 102 | + "content": "CommonLisp", |
| 103 | + "name": "CommonLisp" |
| 104 | + }, |
| 105 | + { |
| 106 | + "content": "Composer", |
| 107 | + "name": "Composer" |
| 108 | + }, |
| 109 | + { |
| 110 | + "content": "Concrete5", |
| 111 | + "name": "Concrete5" |
| 112 | + } |
| 113 | + ]`) |
| 114 | + }) |
| 115 | + |
| 116 | + templates, _, err := client.GitIgnoreTemplates.ListTemplates(&ListTemplatesOptions{}) |
| 117 | + if err != nil { |
| 118 | + t.Errorf("GitIgnoreTemplates.ListTemplates returned error: %v", err) |
| 119 | + } |
| 120 | + |
| 121 | + want := []*GitIgnoreTemplate{ |
| 122 | + { |
| 123 | + Name: "Actionscript", |
| 124 | + Content: "Actionscript", |
| 125 | + }, |
| 126 | + { |
| 127 | + Name: "Ada", |
| 128 | + Content: "Ada", |
| 129 | + }, |
| 130 | + { |
| 131 | + Name: "Agda", |
| 132 | + Content: "Agda", |
| 133 | + }, |
| 134 | + { |
| 135 | + Name: "Android", |
| 136 | + Content: "Android", |
| 137 | + }, |
| 138 | + { |
| 139 | + Name: "AppEngine", |
| 140 | + Content: "AppEngine", |
| 141 | + }, |
| 142 | + { |
| 143 | + Name: "AppceleratorTitanium", |
| 144 | + Content: "AppceleratorTitanium", |
| 145 | + }, |
| 146 | + { |
| 147 | + Name: "ArchLinuxPackages", |
| 148 | + Content: "ArchLinuxPackages", |
| 149 | + }, |
| 150 | + { |
| 151 | + Name: "Autotools", |
| 152 | + Content: "Autotools", |
| 153 | + }, |
| 154 | + { |
| 155 | + Name: "C", |
| 156 | + Content: "C", |
| 157 | + }, |
| 158 | + { |
| 159 | + Name: "C++", |
| 160 | + Content: "C++", |
| 161 | + }, |
| 162 | + { |
| 163 | + Name: "CFWheels", |
| 164 | + Content: "CFWheels", |
| 165 | + }, |
| 166 | + { |
| 167 | + Name: "CMake", |
| 168 | + Content: "CMake", |
| 169 | + }, |
| 170 | + { |
| 171 | + Name: "CUDA", |
| 172 | + Content: "CUDA", |
| 173 | + }, |
| 174 | + { |
| 175 | + Name: "CakePHP", |
| 176 | + Content: "CakePHP", |
| 177 | + }, |
| 178 | + { |
| 179 | + Name: "ChefCookbook", |
| 180 | + Content: "ChefCookbook", |
| 181 | + }, |
| 182 | + { |
| 183 | + Name: "Clojure", |
| 184 | + Content: "Clojure", |
| 185 | + }, |
| 186 | + { |
| 187 | + Name: "CodeIgniter", |
| 188 | + Content: "CodeIgniter", |
| 189 | + }, |
| 190 | + { |
| 191 | + Name: "CommonLisp", |
| 192 | + Content: "CommonLisp", |
| 193 | + }, |
| 194 | + { |
| 195 | + Name: "Composer", |
| 196 | + Content: "Composer", |
| 197 | + }, |
| 198 | + { |
| 199 | + Name: "Concrete5", |
| 200 | + Content: "Concrete5", |
| 201 | + }, |
| 202 | + } |
| 203 | + if !reflect.DeepEqual(want, templates) { |
| 204 | + t.Errorf("GitIgnoreTemplates.ListTemplates returned %+v, want %+v", templates, want) |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | +func TestGetTemplates(t *testing.T) { |
| 209 | + mux, server, client := setup(t) |
| 210 | + defer teardown(server) |
| 211 | + |
| 212 | + mux.HandleFunc("/api/v4/templates/gitignores/Ruby", func(w http.ResponseWriter, r *http.Request) { |
| 213 | + testMethod(t, r, http.MethodGet) |
| 214 | + fmt.Fprintf(w, `{ |
| 215 | + "name": "Ruby", |
| 216 | + "content": "*.gem\n*.rbc\n/.config\n/coverage/\n/InstalledFiles\n/pkg/\n/spec/reports/\n/spec/examples.txt\n/test/tmp/\n/test/version_tmp/\n/tmp/\n\n# Used by dotenv library to load environment variables.\n# .env\n\n## Specific to RubyMotion:\n.dat*\n.repl_history\nbuild/\n*.bridgesupport\nbuild-iPhoneOS/\nbuild-iPhoneSimulator/\n\n## Specific to RubyMotion (use of CocoaPods):\n#\n# We recommend against adding the Pods directory to your .gitignore. However\n# you should judge for yourself, the pros and cons are mentioned at:\n# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control\n#\n# vendor/Pods/\n\n## Documentation cache and generated files:\n/.yardoc/\n/_yardoc/\n/doc/\n/rdoc/\n\n## Environment normalization:\n/.bundle/\n/vendor/bundle\n/lib/bundler/man/\n\n# for a library or gem, you might want to ignore these files since the code is\n# intended to run in multiple environments; otherwise, check them in:\n# Gemfile.lock\n# .ruby-version\n# .ruby-gemset\n\n# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:\n.rvmrc\n" |
| 217 | + }`) |
| 218 | + }) |
| 219 | + |
| 220 | + template, _, err := client.GitIgnoreTemplates.GetTemplate("Ruby") |
| 221 | + if err != nil { |
| 222 | + t.Errorf("GitIgnoreTempaltes.GetTemplate returned an error: %v", err) |
| 223 | + } |
| 224 | + |
| 225 | + want := &GitIgnoreTemplate{ |
| 226 | + Name: "Ruby", |
| 227 | + Content: "*.gem\n*.rbc\n/.config\n/coverage/\n/InstalledFiles\n/pkg/\n/spec/reports/\n/spec/examples.txt\n/test/tmp/\n/test/version_tmp/\n/tmp/\n\n# Used by dotenv library to load environment variables.\n# .env\n\n## Specific to RubyMotion:\n.dat*\n.repl_history\nbuild/\n*.bridgesupport\nbuild-iPhoneOS/\nbuild-iPhoneSimulator/\n\n## Specific to RubyMotion (use of CocoaPods):\n#\n# We recommend against adding the Pods directory to your .gitignore. However\n# you should judge for yourself, the pros and cons are mentioned at:\n# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control\n#\n# vendor/Pods/\n\n## Documentation cache and generated files:\n/.yardoc/\n/_yardoc/\n/doc/\n/rdoc/\n\n## Environment normalization:\n/.bundle/\n/vendor/bundle\n/lib/bundler/man/\n\n# for a library or gem, you might want to ignore these files since the code is\n# intended to run in multiple environments; otherwise, check them in:\n# Gemfile.lock\n# .ruby-version\n# .ruby-gemset\n\n# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:\n.rvmrc\n", |
| 228 | + } |
| 229 | + if !reflect.DeepEqual(want, template) { |
| 230 | + t.Errorf("GitIgnoreTemplates.GetTemplate returned %+v, want %+v", template, want) |
| 231 | + } |
| 232 | +} |
0 commit comments