-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scaffolding for supporting additional whitebox testing
- Loading branch information
1 parent
99946cd
commit 56f650a
Showing
10 changed files
with
209 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package fuzz | ||
|
||
import ( | ||
"k8s.io/api/extensions/v1beta1" | ||
) | ||
|
||
// WhiteboxTest represents a whitebox test than can be run for an Ingress. | ||
// The test validates a part of the Ingress spec against GCE resources. | ||
type WhiteboxTest interface { | ||
// Name of the test. | ||
Name() string | ||
// Test is the test to run. | ||
Test(ing *v1beta1.Ingress, gclb *GCLB) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package whitebox | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/api/extensions/v1beta1" | ||
|
||
"k8s.io/ingress-gce/pkg/fuzz" | ||
"k8s.io/ingress-gce/pkg/utils" | ||
) | ||
|
||
// Implements a whitebox test to check that the GCLB has the expected number of BackendService's. | ||
type numBackendServicesTest struct { | ||
uniqSvcPorts map[utils.ServicePortID]bool | ||
} | ||
|
||
// Name implements WhiteboxTest. | ||
func (t *numBackendServicesTest) Name() string { | ||
return "NumBackendServicesTest" | ||
|
||
} | ||
|
||
// Test implements WhiteboxTest. | ||
func (t *numBackendServicesTest) Test(ing *v1beta1.Ingress, gclb *fuzz.GCLB) error { | ||
t.uniqSvcPorts = make(map[utils.ServicePortID]bool) | ||
expectedBackendServices := 0 | ||
|
||
utils.TraverseIngressBackends(ing, func(id utils.ServicePortID) bool { | ||
if _, ok := t.uniqSvcPorts[id]; !ok { | ||
expectedBackendServices++ | ||
t.uniqSvcPorts[id] = true | ||
} | ||
return false | ||
}) | ||
|
||
if len(gclb.BackendService) != expectedBackendServices { | ||
return fmt.Errorf("Expected %d BackendService's but got %d", expectedBackendServices, len(gclb.BackendService)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package whitebox | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/api/extensions/v1beta1" | ||
|
||
"k8s.io/ingress-gce/pkg/fuzz" | ||
"k8s.io/ingress-gce/pkg/annotations" | ||
) | ||
|
||
// Implements a whitebox test to check that the GCLB has the expected number of ForwardingRule's. | ||
type numForwardingRulesTest struct { | ||
} | ||
|
||
// Name implements WhiteboxTest. | ||
func (t *numForwardingRulesTest) Name() string { | ||
return "NumForwardingRulesTest" | ||
|
||
} | ||
|
||
// Test implements WhiteboxTest. | ||
func (t *numForwardingRulesTest) Test(ing *v1beta1.Ingress, gclb *fuzz.GCLB) error { | ||
expectedForwardingRules := 1 | ||
if len(ing.Spec.TLS) > 0 { | ||
expectedForwardingRules = 2 | ||
} | ||
|
||
an := annotations.FromIngress(ing) | ||
if an.UseNamedTLS() != "" { | ||
expectedForwardingRules = 2 | ||
} | ||
|
||
if len(gclb.ForwardingRule) != expectedForwardingRules { | ||
return fmt.Errorf("Expected %d ForwardingRule's but got %d", expectedForwardingRules, len(gclb.ForwardingRule)) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.