@@ -56,10 +56,43 @@ func TestCreatesGroupAndStream(t *testing.T) {
56
56
assert .True (t , logStreamCreated )
57
57
}
58
58
59
+ func TestCreatesRetentionPolicy (t * testing.T ) {
60
+ logGroupCreated := false
61
+ retentionPolicyCreated := false
62
+ config := & Config {
63
+ LogGroupName : "test" ,
64
+ Retention : 90 ,
65
+ }
66
+
67
+ newLoggerWithServer (config , func (w http.ResponseWriter , r * http.Request ) {
68
+ if action (r ) == "CreateLogGroup" {
69
+ logGroupCreated = true
70
+ }
71
+ if action (r ) == "PutRetentionPolicy" {
72
+ if ! logGroupCreated {
73
+ assert .Fail (t , "CreateLogGroup must be called before PutRetentionPolicy" )
74
+ var data PutRetentionPolicy
75
+ parseBody (r , & data )
76
+ assert .Equal (t , "test" , data .LogGroupName )
77
+ assert .Equal (t , 90 , data .RetentionInDays )
78
+ }
79
+ retentionPolicyCreated = true
80
+ }
81
+ })
82
+
83
+ assert .True (t , logGroupCreated )
84
+ assert .True (t , retentionPolicyCreated )
85
+ }
86
+
59
87
func TestHandlesExistingGroup (t * testing.T ) {
60
88
logStreamCreated := false
89
+ retentionPolicyCreated := false
90
+ config := & Config {
91
+ LogGroupName : "test" ,
92
+ Retention : 30 ,
93
+ }
61
94
62
- newLoggerWithServer (defaultConfig , func (w http.ResponseWriter , r * http.Request ) {
95
+ newLoggerWithServer (config , func (w http.ResponseWriter , r * http.Request ) {
63
96
if action (r ) == "CreateLogGroup" {
64
97
w .WriteHeader (http .StatusBadRequest )
65
98
w .Write ([]byte (`
@@ -72,9 +105,13 @@ func TestHandlesExistingGroup(t *testing.T) {
72
105
if action (r ) == "CreateLogStream" {
73
106
logStreamCreated = true
74
107
}
108
+ if action (r ) == "PutRetentionPolicy" {
109
+ retentionPolicyCreated = true
110
+ }
75
111
})
76
112
77
113
assert .True (t , logStreamCreated )
114
+ assert .False (t , retentionPolicyCreated )
78
115
}
79
116
80
117
func TestSendsLogsToCloudWatchLogs (t * testing.T ) {
@@ -415,6 +452,22 @@ func TestLogStreamCreationFails(t *testing.T) {
415
452
assert .Nil (t , logger )
416
453
}
417
454
455
+ func TestPutRetentionPolicyFails (t * testing.T ) {
456
+ client := newClientWithServer (func (w http.ResponseWriter , r * http.Request ) {
457
+ if action (r ) == "PutRetentionPolicy" {
458
+ w .WriteHeader (http .StatusInternalServerError )
459
+ w .Write ([]byte (`{"__type": "ServiceUnavailableException"}` ))
460
+ }
461
+ })
462
+ logger , err := New (& Config {
463
+ Client : client ,
464
+ LogGroupName : "test" ,
465
+ Retention : 180 ,
466
+ })
467
+ assert .Error (t , err )
468
+ assert .Nil (t , logger )
469
+ }
470
+
418
471
func TestIgnoresBatchItCannotRetry (t * testing.T ) {
419
472
var calls int
420
473
@@ -499,6 +552,11 @@ type PutLogEvents struct {
499
552
LogEvents []* LogEvent `json:"logEvents"`
500
553
}
501
554
555
+ type PutRetentionPolicy struct {
556
+ LogGroupName string `json:"logGroupName"`
557
+ RetentionInDays string `json:"retentionInDays"`
558
+ }
559
+
502
560
type LogEvent struct {
503
561
Timestamp int64 `json:"timestamp"`
504
562
Message string `json:"message"`
0 commit comments