File tree Expand file tree Collapse file tree 5 files changed +85
-99
lines changed
Filter options
Expand file tree Collapse file tree 5 files changed +85
-99
lines changed
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -37,13 +37,13 @@ func (c *Single) HandleUpload(avatar []byte) revel.Result {
37
37
38
38
// Check format of the file.
39
39
conf , format , err := image .DecodeConfig (bytes .NewReader (avatar ))
40
- c .Validation .Required (err == nil ).
40
+ c .Validation .Required (err == nil ).Key ( "avatar" ).
41
41
Message ("Incorrect file format" )
42
- c .Validation .Required (format == "jpeg" || format == "png" ).
42
+ c .Validation .Required (format == "jpeg" || format == "png" ).Key ( "avatar" ).
43
43
Message ("JPEG or PNG file format is expected" )
44
44
45
45
// Check resolution.
46
- c .Validation .Required (conf .Height >= 150 && conf .Width >= 150 ).
46
+ c .Validation .Required (conf .Height >= 150 && conf .Width >= 150 ).Key ( "avatar" ).
47
47
Message ("Minimum allowed resolution is 150x150px" )
48
48
49
49
// Handle errors.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ package tests
2
+
3
+ import (
4
+ "net/url"
5
+
6
+ "github.com/revel/revel/samples/upload/app/routes"
7
+
8
+ "github.com/revel/revel"
9
+ )
10
+
11
+ type MultipleTest struct {
12
+ revel.TestSuite
13
+ }
14
+
15
+ func (t * MultipleTest ) TestThatMultipleFilesUploadWorks () {
16
+ // Make sure it is not allowed to submit less than 2 files.
17
+ t .PostFile (routes .Multiple .HandleUpload (), url.Values {}, url.Values {
18
+ "file" : {
19
+ "github.com/revel/revel/samples/upload/public/img/favicon.png" ,
20
+ },
21
+ })
22
+ t .AssertOk ()
23
+ t .AssertContains ("You cannot submit less than 2 files" )
24
+
25
+ // Make sure upload of 2 files works.
26
+ t .PostFile (routes .Multiple .HandleUpload (), url.Values {}, url.Values {
27
+ "file[]" : {
28
+ "github.com/revel/revel/samples/upload/public/img/favicon.png" ,
29
+ "github.com/revel/revel/samples/upload/public/img/glyphicons-halflings.png" ,
30
+ },
31
+ })
32
+ revel .WARN .Println (string (t .ResponseBody ))
33
+ t .AssertOk ()
34
+ t .AssertContains ("Successfully uploaded" )
35
+ t .AssertContains ("favicon.png" )
36
+ t .AssertContains ("glyphicons-halflings.png" )
37
+ t .AssertContains ("image/png" )
38
+ }
Original file line number Diff line number Diff line change
1
+ package tests
2
+
3
+ import (
4
+ "net/url"
5
+
6
+ "github.com/revel/revel"
7
+ )
8
+
9
+ type SingleTest struct {
10
+ revel.TestSuite
11
+ }
12
+
13
+ func (t * SingleTest ) TestThatSingleAvatarUploadWorks () {
14
+ // Make sure file is required.
15
+ t .PostFile ("/single/HandleUpload" , url.Values {}, url.Values {
16
+ "avatar" : {},
17
+ })
18
+ t .AssertOk ()
19
+ t .AssertContains ("Upload demo" )
20
+ t .AssertContains ("Required" )
21
+
22
+ // Make sure incorrect format is not being accepted.
23
+ t .PostFile ("/single/HandleUpload" , url.Values {}, url.Values {
24
+ "avatar" : {"github.com/revel/revel/samples/upload/public/css/bootstrap.css" },
25
+ })
26
+ t .AssertOk ()
27
+ t .AssertContains ("Incorrect file format" )
28
+
29
+ // Ensure low resolution avatar cannot be uploaded.
30
+ t .PostFile ("/single/HandleUpload" , url.Values {}, url.Values {
31
+ "avatar" : {"github.com/revel/revel/samples/upload/public/img/favicon.png" },
32
+ })
33
+ t .AssertOk ()
34
+ t .AssertContains ("Minimum allowed resolution is 150x150px" )
35
+
36
+ // Check whether correct avatar is uploaded.
37
+ t .PostFile ("/single/HandleUpload" , url.Values {}, url.Values {
38
+ "avatar" : {"github.com/revel/revel/samples/upload/public/img/glyphicons-halflings.png" },
39
+ })
40
+ t .AssertOk ()
41
+ t .AssertContains ("image/png" )
42
+ t .AssertContains ("glyphicons-halflings.png" )
43
+ t .AssertContains ("Successfully uploaded" )
44
+ }
You can’t perform that action at this time.
0 commit comments