@@ -30,6 +30,8 @@ type ExpectedNginxField struct {
30
30
Location string
31
31
// Servers are the server names that the directive should exist in.
32
32
Servers []string
33
+ // Upstream are the upstream names that the directive should exist in.
34
+ Upstreams []string
33
35
// ValueSubstringAllowed allows the expected value to be a substring of the real value.
34
36
// This makes it easier for cases when real values are complex file names or contain things we
35
37
// don't care about, and we just want to check if a substring exists.
@@ -64,6 +66,8 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
64
66
}
65
67
}
66
68
}
69
+
70
+ return validateUpstreamDirectives (expFieldCfg , directive )
67
71
}
68
72
}
69
73
@@ -75,6 +79,19 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
75
79
return fmt .Errorf ("field not found; expected: %+v\n NGINX conf: %s" , expFieldCfg , string (b ))
76
80
}
77
81
82
+ func validateUpstreamDirectives (expFieldCfg ExpectedNginxField , directive * Directive ) error {
83
+ for _ , upstreamName := range expFieldCfg .Upstreams {
84
+ if directive .Directive == "upstream" && directive .Args [0 ] == upstreamName {
85
+ for _ , upstreamDirective := range directive .Block {
86
+ if expFieldCfg .fieldFound (upstreamDirective ) {
87
+ return nil
88
+ }
89
+ }
90
+ }
91
+ }
92
+ return nil
93
+ }
94
+
78
95
func getServerName (serverBlock Directives ) string {
79
96
for _ , directive := range serverBlock {
80
97
if directive .Directive == "server_name" {
0 commit comments