File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -15,13 +15,17 @@ type SuccessResult struct {
15
15
Details string
16
16
Resource string
17
17
Verb string
18
+ Empty bool
18
19
}
19
20
20
21
var standardSuccessMessages = map [string ]string {
21
22
"delete" : "%s has been successfully deleted." ,
22
23
}
23
24
24
25
func (s * SuccessResult ) MarshalHuman () (string , error ) {
26
+ if s .Empty {
27
+ return "" , nil
28
+ }
25
29
message := s .getMessage ()
26
30
if ! strings .HasSuffix (message , "." ) {
27
31
message += "."
@@ -38,6 +42,10 @@ func (s *SuccessResult) MarshalHuman() (string, error) {
38
42
}
39
43
40
44
func (s * SuccessResult ) MarshalJSON () ([]byte , error ) {
45
+ if s .Empty {
46
+ type emptyRes struct {}
47
+ return json .Marshal (& emptyRes {})
48
+ }
41
49
type tmpRes struct {
42
50
Message string `json:"message"`
43
51
Details string `json:"details"`
Original file line number Diff line number Diff line change
1
+ package core
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestResult (t * testing.T ) {
10
+ result := & SuccessResult {
11
+ Empty : true ,
12
+ Details : "dummy" ,
13
+ Message : "dummy" ,
14
+ Resource : "dummy" ,
15
+ Verb : "dummy" ,
16
+ }
17
+
18
+ humanOutput , err := result .MarshalHuman ()
19
+ assert .NoError (t , err )
20
+ assert .Equal (t , "" , humanOutput )
21
+ jsonOutput , err := result .MarshalJSON ()
22
+ assert .NoError (t , err )
23
+ assert .Equal (t , []byte ("{}" ), jsonOutput )
24
+ }
You can’t perform that action at this time.
0 commit comments