@@ -53,4 +53,62 @@ def test_post_invocation_error_with_too_large_xray_cause
53
53
54
54
assert_mock post_mock
55
55
end
56
+
57
+ def mock_next_invocation_response ( )
58
+ mock_response = Net ::HTTPSuccess . new ( 1.0 , '200' , 'OK' )
59
+ mock_response [ 'Lambda-Runtime-Aws-Request-Id' ] = @request_id
60
+ mock_response
61
+ end
62
+
63
+ def mock_next_invocation_request ( mock_response )
64
+ get_mock = Minitest ::Mock . new
65
+ get_mock . expect ( :read_timeout= , nil , [ RapidClient ::LONG_TIMEOUT_MS ] )
66
+ get_mock . expect ( :start , mock_response ) do |&block |
67
+ block . call ( get_mock )
68
+ end
69
+ get_mock . expect ( :get , mock_response , [ '/2018-06-01/runtime/invocation/next' , { 'User-Agent' => @mock_user_agent } ] )
70
+ get_mock
71
+ end
72
+
73
+ def assert_next_invocation ( get_mock , expected_tenant_id )
74
+ Net ::HTTP . stub ( :new , get_mock , [ '127.0.0.1' , 9001 ] ) do
75
+ request_id , response = @under_test . next_invocation
76
+ assert_equal @request_id , request_id
77
+ assert_equal expected_tenant_id , response [ 'Lambda-Runtime-Aws-Tenant-Id' ]
78
+ end
79
+ end
80
+
81
+ def test_next_invocation_without_tenant_id_header
82
+ mock_response = mock_next_invocation_response ( )
83
+ get_mock = mock_next_invocation_request ( mock_response )
84
+ assert_next_invocation ( get_mock , nil )
85
+ assert_mock get_mock
86
+ end
87
+
88
+ def test_next_invocation_with_tenant_id_header
89
+ mock_response = mock_next_invocation_response ( )
90
+ mock_response [ 'Lambda-Runtime-Aws-Tenant-Id' ] = 'blue'
91
+
92
+ get_mock = mock_next_invocation_request ( mock_response )
93
+ assert_next_invocation ( get_mock , 'blue' )
94
+ assert_mock get_mock
95
+ end
96
+
97
+ def test_next_invocation_with_empty_tenant_id_header
98
+ mock_response = mock_next_invocation_response ( )
99
+ mock_response [ 'Lambda-Runtime-Aws-Tenant-Id' ] = ''
100
+
101
+ get_mock = mock_next_invocation_request ( mock_response )
102
+ assert_next_invocation ( get_mock , '' )
103
+ assert_mock get_mock
104
+ end
105
+
106
+ def test_next_invocation_with_null_tenant_id_header
107
+ mock_response = mock_next_invocation_response ( )
108
+ mock_response [ 'Lambda-Runtime-Aws-Tenant-Id' ] = nil
109
+
110
+ get_mock = mock_next_invocation_request ( mock_response )
111
+ assert_next_invocation ( get_mock , nil )
112
+ assert_mock get_mock
113
+ end
56
114
end
0 commit comments