2014-08-01 00:35:54 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-08-01 00:35:54 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2015-10-10 08:18:12 +00:00
|
|
|
package gce
|
2014-08-01 00:35:54 +00:00
|
|
|
|
2015-10-24 00:01:49 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2015-08-28 22:40:43 +00:00
|
|
|
|
2014-08-01 00:35:54 +00:00
|
|
|
func TestGetRegion(t *testing.T) {
|
|
|
|
gce := &GCECloud{
|
|
|
|
zone: "us-central1-b",
|
|
|
|
}
|
|
|
|
zones, ok := gce.Zones()
|
|
|
|
if !ok {
|
2014-08-04 16:58:10 +00:00
|
|
|
t.Fatalf("Unexpected missing zones impl")
|
2014-08-01 00:35:54 +00:00
|
|
|
}
|
2014-08-04 16:58:10 +00:00
|
|
|
zone, err := zones.GetZone()
|
2014-08-01 00:35:54 +00:00
|
|
|
if err != nil {
|
2014-08-04 16:58:10 +00:00
|
|
|
t.Fatalf("unexpected error %v", err)
|
2014-08-01 00:35:54 +00:00
|
|
|
}
|
2014-08-04 16:58:10 +00:00
|
|
|
if zone.Region != "us-central1" {
|
|
|
|
t.Errorf("Unexpected region: %s", zone.Region)
|
2014-08-01 00:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-09 05:02:10 +00:00
|
|
|
|
2015-07-15 18:58:54 +00:00
|
|
|
func TestComparingHostURLs(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
host1 string
|
|
|
|
zone string
|
|
|
|
name string
|
|
|
|
expectEqual bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
|
|
zone: "us-central1-f",
|
|
|
|
name: "kubernetes-node-fhx1",
|
|
|
|
expectEqual: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
host1: "https://www.googleapis.com/compute/v1/projects/cool-project/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
|
|
zone: "us-central1-f",
|
|
|
|
name: "kubernetes-node-fhx1",
|
|
|
|
expectEqual: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
host1: "https://www.googleapis.com/compute/v23/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
|
|
zone: "us-central1-f",
|
|
|
|
name: "kubernetes-node-fhx1",
|
|
|
|
expectEqual: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
host1: "https://www.googleapis.com/compute/v24/projects/1234567/regions/us-central1/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
|
|
zone: "us-central1-f",
|
|
|
|
name: "kubernetes-node-fhx1",
|
|
|
|
expectEqual: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
|
|
zone: "us-central1-c",
|
|
|
|
name: "kubernetes-node-fhx1",
|
|
|
|
expectEqual: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx",
|
|
|
|
zone: "us-central1-f",
|
|
|
|
name: "kubernetes-node-fhx1",
|
|
|
|
expectEqual: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
|
|
zone: "us-central1-f",
|
|
|
|
name: "kubernetes-node-fhx",
|
|
|
|
expectEqual: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
link1 := hostURLToComparablePath(test.host1)
|
|
|
|
link2 := makeComparableHostPath(test.zone, test.name)
|
|
|
|
if test.expectEqual && link1 != link2 {
|
|
|
|
t.Errorf("expected link1 and link2 to be equal, got %s and %s", link1, link2)
|
|
|
|
} else if !test.expectEqual && link1 == link2 {
|
|
|
|
t.Errorf("expected link1 and link2 not to be equal, got %s and %s", link1, link2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-24 00:01:49 +00:00
|
|
|
|
|
|
|
func TestScrubDNS(t *testing.T) {
|
|
|
|
tcs := []struct {
|
|
|
|
nameserversIn []string
|
|
|
|
searchesIn []string
|
|
|
|
nameserversOut []string
|
|
|
|
searchesOut []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
nameserversIn: []string{"1.2.3.4", "5.6.7.8"},
|
|
|
|
nameserversOut: []string{"1.2.3.4", "5.6.7.8"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
searchesIn: []string{"c.prj.internal.", "12345678910.google.internal.", "google.internal."},
|
|
|
|
searchesOut: []string{"c.prj.internal.", "google.internal."},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
searchesIn: []string{"c.prj.internal.", "12345678910.google.internal.", "zone.c.prj.internal.", "google.internal."},
|
|
|
|
searchesOut: []string{"c.prj.internal.", "zone.c.prj.internal.", "google.internal."},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
searchesIn: []string{"c.prj.internal.", "12345678910.google.internal.", "zone.c.prj.internal.", "google.internal.", "unexpected"},
|
|
|
|
searchesOut: []string{"c.prj.internal.", "zone.c.prj.internal.", "google.internal.", "unexpected"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
gce := &GCECloud{}
|
|
|
|
for i := range tcs {
|
|
|
|
n, s := gce.ScrubDNS(tcs[i].nameserversIn, tcs[i].searchesIn)
|
|
|
|
if !reflect.DeepEqual(n, tcs[i].nameserversOut) {
|
|
|
|
t.Errorf("Expected %v, got %v", tcs[i].nameserversOut, n)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(s, tcs[i].searchesOut) {
|
|
|
|
t.Errorf("Expected %v, got %v", tcs[i].searchesOut, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|