@@ -29,12 +29,13 @@ func TestACRWebhook_Validate(t *testing.T) {
2929 webhook := NewACRWebhook (secret )
3030
3131 tests := []struct {
32- name string
33- method string
34- contentType string
35- authHeader string
36- noSecret bool
37- expectError bool
32+ name string
33+ method string
34+ contentType string
35+ authHeader string
36+ noSecret bool
37+ expectError bool
38+ expectedErrMsg string
3839 }{
3940 {
4041 name : "valid POST request with correct secret" ,
@@ -65,18 +66,20 @@ func TestACRWebhook_Validate(t *testing.T) {
6566 expectError : true ,
6667 },
6768 {
68- name : "missing Authorization header when secret is configured" ,
69- method : "POST" ,
70- contentType : "application/json" ,
71- authHeader : "" ,
72- expectError : true ,
69+ name : "missing Authorization header when secret is configured" ,
70+ method : "POST" ,
71+ contentType : "application/json" ,
72+ authHeader : "" ,
73+ expectError : true ,
74+ expectedErrMsg : "missing Authorization header when secret is configured" ,
7375 },
7476 {
75- name : "incorrect secret" ,
76- method : "POST" ,
77- contentType : "application/json" ,
78- authHeader : "not-the-secret" ,
79- expectError : true ,
77+ name : "incorrect secret" ,
78+ method : "POST" ,
79+ contentType : "application/json" ,
80+ authHeader : "not-the-secret" ,
81+ expectError : true ,
82+ expectedErrMsg : "invalid webhook secret" ,
8083 },
8184 }
8285
@@ -99,8 +102,10 @@ func TestACRWebhook_Validate(t *testing.T) {
99102
100103 if tt .expectError {
101104 assert .Error (t , err )
102- }
103- if ! tt .expectError {
105+ if tt .expectedErrMsg != "" {
106+ assert .EqualError (t , err , tt .expectedErrMsg )
107+ }
108+ } else {
104109 assert .NoError (t , err )
105110 }
106111 })
0 commit comments