external-dns/source/fake_test.go
Ian Smith f06fb65917 Fake source (#205)
* Expose inmemory provider to cli

So we can test `--source fake` without needing to touch AWS/Google.

* Add FakeSource

`external-dns --provider inmemory --source fake --dry-run --once`

OR

`external-dns --provider aws --source fake --fqdn-template <hostname suffix> --dry-run --once`

NB: `--fqdn-template` because otherwise we'll default to creating, e.g.,
`abcd.example.com`, which `--provider aws` filters out because you
likely don't have a Zone for `example.com.`  Could also be resolved by
removing the need to use a real provider; the inmemory provider,
perhaps, though it's not entirely hooked up.

Closes kubernetes-incubator/external-dns#22

* Style feedback from Travis CI

* Improve optionality of kubernetes client

* ref(sources): refactor source registration and lookup to be lazy.

* Revert "ref: refactor source registration/lookup to be lazily initialized"
2017-05-29 13:59:50 +02:00

73 lines
1.5 KiB
Go

/*
Copyright 2017 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 source
import (
"net"
"regexp"
"testing"
"github.com/kubernetes-incubator/external-dns/endpoint"
)
func generateTestEndpoints() []*endpoint.Endpoint {
sc, _ := NewFakeSource("")
endpoints, _ := sc.Endpoints()
return endpoints
}
func TestFakeSourceReturnsTenEndpoints(t *testing.T) {
endpoints := generateTestEndpoints()
count := len(endpoints)
if count != 10 {
t.Error(count)
}
}
func TestFakeEndpointsBelongToDomain(t *testing.T) {
validRecord := regexp.MustCompile(`^[a-z]{4}\.example\.com$`)
endpoints := generateTestEndpoints()
for _, e := range endpoints {
valid := validRecord.MatchString(e.DNSName)
if !valid {
t.Error(e.DNSName)
}
}
}
func TestFakeEndpointsResolveToIPAddresses(t *testing.T) {
endpoints := generateTestEndpoints()
for _, e := range endpoints {
ip := net.ParseIP(e.Target)
if ip == nil {
t.Error(e)
}
}
}
// Validate that FakeSource is a source
var _ Source = &fakeSource{}