github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/s3/get_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/smartystreets/goconvey/convey" 9 ) 10 11 func TestS3GetValidateParams(t *testing.T) { 12 13 Convey("With an s3 get command", t, func() { 14 15 var cmd *S3GetCommand 16 17 Convey("when validating params", func() { 18 19 cmd = &S3GetCommand{} 20 21 Convey("a missing aws key should cause an error", func() { 22 23 params := map[string]interface{}{ 24 "aws_secret": "secret", 25 "remote_file": "remote", 26 "bucket": "bck", 27 "local_file": "local", 28 } 29 So(cmd.ParseParams(params), ShouldNotBeNil) 30 So(cmd.validateParams(), ShouldNotBeNil) 31 }) 32 33 Convey("a missing aws secret should cause an error", func() { 34 35 params := map[string]interface{}{ 36 "aws_key": "key", 37 "remote_file": "remote", 38 "bucket": "bck", 39 "local_file": "local", 40 } 41 So(cmd.ParseParams(params), ShouldNotBeNil) 42 So(cmd.validateParams(), ShouldNotBeNil) 43 44 }) 45 46 Convey("a missing remote file should cause an error", func() { 47 48 params := map[string]interface{}{ 49 "aws_key": "key", 50 "aws_secret": "secret", 51 "bucket": "bck", 52 "local_file": "local", 53 } 54 So(cmd.ParseParams(params), ShouldNotBeNil) 55 So(cmd.validateParams(), ShouldNotBeNil) 56 57 }) 58 59 Convey("a missing bucket should cause an error", func() { 60 61 params := map[string]interface{}{ 62 "aws_key": "key", 63 "aws_secret": "secret", 64 "remote_file": "remote", 65 "local_file": "local", 66 } 67 So(cmd.ParseParams(params), ShouldNotBeNil) 68 So(cmd.validateParams(), ShouldNotBeNil) 69 70 }) 71 72 Convey("having neither a local file nor extract-to specified"+ 73 " should cause an error", func() { 74 75 params := map[string]interface{}{ 76 "aws_key": "key", 77 "aws_secret": "secret", 78 "remote_file": "remote", 79 "bucket": "bck", 80 } 81 So(cmd.ParseParams(params), ShouldNotBeNil) 82 So(cmd.validateParams(), ShouldNotBeNil) 83 84 }) 85 86 Convey("having both a local file and an extract-to specified"+ 87 " should cause an error", func() { 88 89 params := map[string]interface{}{ 90 "aws_key": "key", 91 "aws_secret": "secret", 92 "remote_file": "remote", 93 "bucket": "bck", 94 "local_file": "local", 95 "extract_to": "extract", 96 } 97 So(cmd.ParseParams(params), ShouldNotBeNil) 98 So(cmd.validateParams(), ShouldNotBeNil) 99 100 }) 101 102 Convey("a valid set of params should not cause an error", func() { 103 104 params := map[string]interface{}{ 105 "aws_key": "key", 106 "aws_secret": "secret", 107 "remote_file": "remote", 108 "bucket": "bck", 109 "local_file": "local", 110 } 111 So(cmd.ParseParams(params), ShouldBeNil) 112 So(cmd.validateParams(), ShouldBeNil) 113 114 }) 115 116 }) 117 118 }) 119 } 120 121 func TestExpandS3GetParams(t *testing.T) { 122 123 Convey("With an s3 get command and a task config", t, func() { 124 125 var cmd *S3GetCommand 126 var conf *model.TaskConfig 127 128 Convey("when expanding the command's params", func() { 129 130 cmd = &S3GetCommand{} 131 conf = &model.TaskConfig{ 132 Expansions: command.NewExpansions(map[string]string{}), 133 } 134 135 Convey("all appropriate values should be expanded, if they"+ 136 " contain expansions", func() { 137 138 cmd.AwsKey = "${aws_key}" 139 cmd.AwsSecret = "${aws_secret}" 140 cmd.RemoteFile = "${remote_file}" 141 cmd.Bucket = "${bucket}" 142 143 conf.Expansions.Update( 144 map[string]string{ 145 "aws_key": "key", 146 "aws_secret": "secret", 147 "remote_file": "remote", 148 "bucket": "bck", 149 }, 150 ) 151 152 So(cmd.expandParams(conf), ShouldBeNil) 153 So(cmd.AwsKey, ShouldEqual, "key") 154 So(cmd.AwsSecret, ShouldEqual, "secret") 155 So(cmd.RemoteFile, ShouldEqual, "remote") 156 So(cmd.Bucket, ShouldEqual, "bck") 157 158 }) 159 160 }) 161 162 }) 163 }