mirror of https://github.com/kubernetes/kops.git
Add general contract test for IsEmpty
This was the root bug that was causing the over-logging on GCE.
This commit is contained in:
parent
7e710e85d9
commit
3306549749
|
@ -298,3 +298,11 @@ func TestResourceRecordSetsDifferentTypes(t *testing.T) {
|
|||
zone := firstZone(t)
|
||||
tests.CommonTestResourceRecordSetsDifferentTypes(t, zone)
|
||||
}
|
||||
|
||||
// TestContract verifies the general interface contract
|
||||
func TestContract(t *testing.T) {
|
||||
zone := firstZone(t)
|
||||
sets := rrs(t, zone)
|
||||
|
||||
tests.TestContract(t, sets)
|
||||
}
|
||||
|
|
|
@ -263,3 +263,11 @@ func TestResourceRecordSetsDifferentTypes(t *testing.T) {
|
|||
zone := firstZone(t)
|
||||
tests.CommonTestResourceRecordSetsDifferentTypes(t, zone)
|
||||
}
|
||||
|
||||
// TestContract verifies the general interface contract
|
||||
func TestContract(t *testing.T) {
|
||||
zone := firstZone(t)
|
||||
sets := rrs(t, zone)
|
||||
|
||||
tests.TestContract(t, sets)
|
||||
}
|
||||
|
|
|
@ -275,3 +275,11 @@ func TestResourceRecordSetsDifferentTypes(t *testing.T) {
|
|||
zone := firstZone(t)
|
||||
tests.CommonTestResourceRecordSetsDifferentTypes(t, zone)
|
||||
}
|
||||
|
||||
// TestContract verifies the general interface contract
|
||||
func TestContract(t *testing.T) {
|
||||
zone := firstZone(t)
|
||||
sets := rrs(t, zone)
|
||||
|
||||
tests.TestContract(t, sets)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
|
@ -25,3 +25,10 @@ go_library(
|
|||
"//vendor/k8s.io/klog:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["designate_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//dnsprovider/pkg/dnsprovider/tests:go_default_library"],
|
||||
)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright 2020 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 designate
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kops/dnsprovider/pkg/dnsprovider/tests"
|
||||
)
|
||||
|
||||
// TestContract verifies the general interface contract
|
||||
func TestContract(t *testing.T) {
|
||||
sets := &ResourceRecordSets{}
|
||||
|
||||
tests.TestContract(t, sets)
|
||||
}
|
|
@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
|||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["commontests.go"],
|
||||
srcs = [
|
||||
"commontests.go",
|
||||
"contract.go",
|
||||
],
|
||||
importpath = "k8s.io/kops/dnsprovider/pkg/dnsprovider/tests",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
Copyright 2020 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 tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kops/dnsprovider/pkg/dnsprovider"
|
||||
"k8s.io/kops/dnsprovider/pkg/dnsprovider/rrstype"
|
||||
)
|
||||
|
||||
// TestContract verifies the general ResourceRecordChangeset contract
|
||||
func TestContract(t *testing.T, rrsets dnsprovider.ResourceRecordSets) {
|
||||
|
||||
{
|
||||
changeset := rrsets.StartChangeset()
|
||||
if !changeset.IsEmpty() {
|
||||
t.Fatalf("expected new changeset to be empty")
|
||||
}
|
||||
|
||||
rrs := changeset.ResourceRecordSets().New("foo", []string{"192.168.0.1"}, 1, rrstype.A)
|
||||
changeset.Add(rrs)
|
||||
if changeset.IsEmpty() {
|
||||
t.Fatalf("expected changeset not to be empty after add")
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
changeset := rrsets.StartChangeset()
|
||||
if !changeset.IsEmpty() {
|
||||
t.Fatalf("expected new changeset to be empty")
|
||||
}
|
||||
|
||||
rrs := changeset.ResourceRecordSets().New("foo", []string{"192.168.0.1"}, 1, rrstype.A)
|
||||
changeset.Remove(rrs)
|
||||
if changeset.IsEmpty() {
|
||||
t.Fatalf("expected changeset not to be empty after remove")
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
changeset := rrsets.StartChangeset()
|
||||
if !changeset.IsEmpty() {
|
||||
t.Fatalf("expected new changeset to be empty")
|
||||
}
|
||||
|
||||
rrs := changeset.ResourceRecordSets().New("foo", []string{"192.168.0.1"}, 1, rrstype.A)
|
||||
changeset.Upsert(rrs)
|
||||
if changeset.IsEmpty() {
|
||||
t.Fatalf("expected changeset not to be empty after upsert")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -369,6 +369,8 @@ func TestNewResourceRecordSet(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResourceRecordChangeset(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
fake := &fakeDomainService{}
|
||||
fake.recordsFunc = func(ctx context.Context, domain string, listOpts *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) {
|
||||
domainRecords := []godo.DomainRecord{
|
||||
|
@ -456,7 +458,7 @@ func TestResourceRecordChangeset(t *testing.T) {
|
|||
record = rrset.New("to-upsert", []string{"127.0.0.1"}, 3600, rrstype.A)
|
||||
changeset.Upsert(record)
|
||||
|
||||
err = changeset.Apply()
|
||||
err = changeset.Apply(ctx)
|
||||
if err != nil {
|
||||
t.Errorf("error applying changeset: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue