coredns/middleware/kubernetes/util/util_test.go
Michael Richmond 3f4ec783d2 Adding wildcard support (#190)
* Commenting out unused functions. TODO: remove when it is not needed

* Update README with namespace and template example

* Adding note about changing the record name format via a template

* Adding test scripts to automate k8s startup

* Automating k8s namespace creation

* Adding automation to start 4 k8s services

* Updating documentation for k8s tests

* Avoid downloading kubectl if already exists

* Adding debug statement when namespace is not exposed.

* Adding basic kubernetes integration tests

* Makefile now contains a "testk8s" target. This target requires k8s to
  be running.
* Adding test/kubernetes_test.go file with a couple of basic A record
  tests.

* Updating k8s integration tests to only run k8s integration tests

* Adding support for namespace wildcards

* Refactoring to move filtering logic to kubernetes.go file

* go fmt fixes

* Adding wildcard support for namespaces and service names

* Kubernetes integration tests updated for A records.
* Expanded record name assembly for answer section not yet implemented.
* Refactoring to focus k8sclient code just on accessing k8s API.
 Filtering now handled in kubernetes.go

* Adding wildcard test cases

* Adding skydns startup script. (To allow side by side testing of wildcards.)
* Commenting out record name assmebly based on NameTemplate. Need to improve template before this makes sense.

* Adding basic SRV integration tests

* Need to add verification for additional answer section

* Fixing comments and formatting

* Moving wildcard constants to vars

* Travis test execution appears to be failing on access to these
 constants

* Fixing access to util package

* Trying to work around Travis test bug

* Reverting to access kubernetes/util as "util"

Travis breakage is due to "Infoblox-CTO" in src path
2016-07-14 23:50:14 +02:00

55 lines
1.4 KiB
Go

package util
import (
"testing"
)
type InSliceData struct {
Slice []string
String string
InSlice bool
}
// Test data for TestStringInSlice cases.
var testdataInSlice = []struct {
Slice []string
String string
ExpectedResult bool
}{
{[]string{"a", "b", "c"}, "a", true},
{[]string{"a", "b", "c"}, "d", false},
{[]string{"a", "b", "c"}, "", false},
{[]string{}, "a", false},
{[]string{}, "", false},
}
func TestStringInSlice(t *testing.T) {
for _, example := range testdataInSlice {
actualResult := StringInSlice(example.String, example.Slice)
if actualResult != example.ExpectedResult {
t.Errorf("Expected stringInSlice result '%v' for example string='%v', slice='%v'. Instead got result '%v'.", example.ExpectedResult, example.String, example.Slice, actualResult)
}
}
}
// Test data for TestSymbolContainsWildcard cases.
var testdataSymbolContainsWildcard = []struct {
Symbol string
ExpectedResult bool
}{
{"mynamespace", false},
{"*", true},
{"any", true},
{"my*space", true},
{"*space", true},
{"myname*", true},
}
func TestSymbolContainsWildcard(t *testing.T) {
for _, example := range testdataSymbolContainsWildcard {
actualResult := SymbolContainsWildcard(example.Symbol)
if actualResult != example.ExpectedResult {
t.Errorf("Expected SymbolContainsWildcard result '%v' for example string='%v'. Instead got result '%v'.", example.ExpectedResult, example.Symbol, actualResult)
}
}
}