Skip to content

Commit

Permalink
Add general contract test for IsEmpty
Browse files Browse the repository at this point in the history
This was the root bug that was causing the over-logging on GCE.
  • Loading branch information
justinsb committed May 17, 2020
1 parent 7e710e8 commit 3306549
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions dnsprovider/pkg/dnsprovider/providers/coredns/coredns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"],
)
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 4 additions & 1 deletion dnsprovider/pkg/dnsprovider/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
68 changes: 68 additions & 0 deletions dnsprovider/pkg/dnsprovider/tests/contract.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

}
4 changes: 3 additions & 1 deletion pkg/resources/digitalocean/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3306549

Please sign in to comment.