github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/s3/put_command_test.go (about) 1 package s3 2 3 import ( 4 "testing" 5 6 "github.com/evergreen-ci/evergreen/command" 7 "github.com/evergreen-ci/evergreen/model" 8 "github.com/evergreen-ci/evergreen/model/artifact" 9 . "github.com/smartystreets/goconvey/convey" 10 ) 11 12 func TestS3PutValidateParams(t *testing.T) { 13 14 Convey("With an s3 put command", t, func() { 15 16 var cmd *S3PutCommand 17 18 Convey("when validating command params", func() { 19 20 cmd = &S3PutCommand{} 21 22 Convey("a missing aws key should cause an error", func() { 23 24 params := map[string]interface{}{ 25 "aws_secret": "secret", 26 "local_file": "local", 27 "remote_file": "remote", 28 "bucket": "bck", 29 "permissions": "public-read", 30 "content_type": "application/x-tar", 31 "display_name": "test_file", 32 } 33 So(cmd.ParseParams(params), ShouldNotBeNil) 34 So(cmd.validateParams(), ShouldNotBeNil) 35 }) 36 Convey("a defined local file and inclusion filter should cause an error", func() { 37 38 params := map[string]interface{}{ 39 "aws_secret": "secret", 40 "local_file": "local", 41 "local_files_include_filter": []string{"local"}, 42 "remote_file": "remote", 43 "bucket": "bck", 44 "permissions": "public-read", 45 "content_type": "application/x-tar", 46 "display_name": "test_file", 47 } 48 So(cmd.ParseParams(params), ShouldNotBeNil) 49 So(cmd.validateParams(), ShouldNotBeNil) 50 }) 51 Convey("a defined inclusion filter with optional upload should cause an error", func() { 52 53 params := map[string]interface{}{ 54 "aws_secret": "secret", 55 "local_files_include_filter": []string{"local"}, 56 "optional": true, 57 "remote_file": "remote", 58 "bucket": "bck", 59 "permissions": "public-read", 60 "content_type": "application/x-tar", 61 "display_name": "test_file", 62 } 63 So(cmd.ParseParams(params), ShouldNotBeNil) 64 So(cmd.validateParams(), ShouldNotBeNil) 65 }) 66 67 Convey("a missing aws secret should cause an error", func() { 68 69 params := map[string]interface{}{ 70 "aws_key": "key", 71 "local_file": "local", 72 "remote_file": "remote", 73 "bucket": "bck", 74 "permissions": "public-read", 75 "content_type": "application/x-tar", 76 "display_name": "test_file", 77 } 78 So(cmd.ParseParams(params), ShouldNotBeNil) 79 So(cmd.validateParams(), ShouldNotBeNil) 80 81 }) 82 83 Convey("a missing local file should cause an error", func() { 84 85 params := map[string]interface{}{ 86 "aws_key": "key", 87 "aws_secret": "secret", 88 "remote_file": "remote", 89 "bucket": "bck", 90 "permissions": "public-read", 91 "content_type": "application/x-tar", 92 "display_name": "test_file", 93 } 94 So(cmd.ParseParams(params), ShouldNotBeNil) 95 So(cmd.validateParams(), ShouldNotBeNil) 96 97 }) 98 99 Convey("a missing remote file should cause an error", func() { 100 101 params := map[string]interface{}{ 102 "aws_key": "key", 103 "aws_secret": "secret", 104 "local_file": "local", 105 "bucket": "bck", 106 "permissions": "public-read", 107 "content_type": "application/x-tar", 108 "display_name": "test_file", 109 } 110 So(cmd.ParseParams(params), ShouldNotBeNil) 111 So(cmd.validateParams(), ShouldNotBeNil) 112 113 }) 114 115 Convey("a missing bucket should cause an error", func() { 116 117 params := map[string]interface{}{ 118 "aws_key": "key", 119 "aws_secret": "secret", 120 "local_file": "local", 121 "remote_file": "remote", 122 "permissions": "public-read", 123 "content_type": "application/x-tar", 124 "display_name": "test_file", 125 } 126 So(cmd.ParseParams(params), ShouldNotBeNil) 127 So(cmd.validateParams(), ShouldNotBeNil) 128 129 }) 130 131 Convey("a missing s3 permission should cause an error", func() { 132 133 params := map[string]interface{}{ 134 "aws_key": "key", 135 "aws_secret": "secret", 136 "local_file": "local", 137 "remote_file": "remote", 138 "bucket": "bck", 139 "content_type": "application/x-tar", 140 "display_name": "test_file", 141 } 142 So(cmd.ParseParams(params), ShouldNotBeNil) 143 So(cmd.validateParams(), ShouldNotBeNil) 144 145 }) 146 147 Convey("an invalid s3 permission should cause an error", func() { 148 149 params := map[string]interface{}{ 150 "aws_key": "key", 151 "aws_secret": "secret", 152 "local_file": "local", 153 "remote_file": "remote", 154 "bucket": "bck", 155 "permissions": "bleccchhhh", 156 "content_type": "application/x-tar", 157 "display_name": "test_file", 158 } 159 So(cmd.ParseParams(params), ShouldNotBeNil) 160 So(cmd.validateParams(), ShouldNotBeNil) 161 162 }) 163 164 Convey("a missing content type should cause an error", func() { 165 166 params := map[string]interface{}{ 167 "aws_key": "key", 168 "aws_secret": "secret", 169 "local_file": "local", 170 "remote_file": "remote", 171 "bucket": "bck", 172 "permissions": "private", 173 "display_name": "test_file", 174 } 175 So(cmd.ParseParams(params), ShouldNotBeNil) 176 So(cmd.validateParams(), ShouldNotBeNil) 177 178 }) 179 180 Convey("an invalid visibility type should cause an error", func() { 181 182 params := map[string]interface{}{ 183 "aws_key": "key", 184 "aws_secret": "secret", 185 "local_file": "local", 186 "remote_file": "remote", 187 "bucket": "bck", 188 "content_type": "application/x-tar", 189 "permissions": "private", 190 "display_name": "test_file", 191 "visibility": "ARGHGHGHGHGH", 192 } 193 So(cmd.ParseParams(params), ShouldNotBeNil) 194 So(cmd.validateParams(), ShouldNotBeNil) 195 196 }) 197 198 Convey("a valid set of params should not cause an error", func() { 199 200 params := map[string]interface{}{ 201 "aws_key": "key", 202 "aws_secret": "secret", 203 "local_file": "local", 204 "remote_file": "remote", 205 "bucket": "bck", 206 "permissions": "public-read", 207 "content_type": "application/x-tar", 208 "display_name": "test_file", 209 } 210 So(cmd.ParseParams(params), ShouldBeNil) 211 So(cmd.validateParams(), ShouldBeNil) 212 So(cmd.AwsKey, ShouldEqual, params["aws_key"]) 213 So(cmd.AwsSecret, ShouldEqual, params["aws_secret"]) 214 So(cmd.LocalFile, ShouldEqual, params["local_file"]) 215 So(cmd.RemoteFile, ShouldEqual, params["remote_file"]) 216 So(cmd.Bucket, ShouldEqual, params["bucket"]) 217 So(cmd.Permissions, ShouldEqual, params["permissions"]) 218 So(cmd.DisplayName, ShouldEqual, params["display_name"]) 219 220 }) 221 }) 222 223 }) 224 } 225 226 func TestExpandS3PutParams(t *testing.T) { 227 228 Convey("With an s3 put command and a task config", t, func() { 229 230 var cmd *S3PutCommand 231 var conf *model.TaskConfig 232 233 Convey("when expanding the command's params", func() { 234 235 cmd = &S3PutCommand{} 236 conf = &model.TaskConfig{ 237 Expansions: command.NewExpansions(map[string]string{}), 238 } 239 240 Convey("all appropriate values should be expanded, if they"+ 241 " contain expansions", func() { 242 243 cmd.AwsKey = "${aws_key}" 244 cmd.AwsSecret = "${aws_secret}" 245 cmd.RemoteFile = "${remote_file}" 246 cmd.Bucket = "${bucket}" 247 cmd.ContentType = "${content_type}" 248 cmd.DisplayName = "${display_name}" 249 cmd.Visibility = "${visibility}" 250 251 conf.Expansions.Update( 252 map[string]string{ 253 "aws_key": "key", 254 "aws_secret": "secret", 255 "remote_file": "remote", 256 "bucket": "bck", 257 "content_type": "ct", 258 "display_name": "file", 259 "visibility": artifact.Private, 260 }, 261 ) 262 263 So(cmd.expandParams(conf), ShouldBeNil) 264 So(cmd.AwsKey, ShouldEqual, "key") 265 So(cmd.AwsSecret, ShouldEqual, "secret") 266 So(cmd.RemoteFile, ShouldEqual, "remote") 267 So(cmd.Bucket, ShouldEqual, "bck") 268 So(cmd.ContentType, ShouldEqual, "ct") 269 So(cmd.DisplayName, ShouldEqual, "file") 270 So(cmd.Visibility, ShouldEqual, "private") 271 272 }) 273 274 }) 275 276 }) 277 }