github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/maintenance/aws-janitor/janitor_test.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/aws/aws-sdk-go/aws"
    23  	"github.com/aws/aws-sdk-go/service/route53"
    24  )
    25  
    26  func TestManagedNames(t *testing.T) {
    27  	grid := []struct {
    28  		rrs      *route53.ResourceRecordSet
    29  		expected bool
    30  	}{
    31  		{
    32  			rrs:      &route53.ResourceRecordSet{Type: aws.String("A"), Name: aws.String("api.e2e-61246-dba53.test-cncf-aws.k8s.io.")},
    33  			expected: true,
    34  		},
    35  		{
    36  			rrs:      &route53.ResourceRecordSet{Type: aws.String("A"), Name: aws.String("api.internal.e2e-61246-dba53.test-cncf-aws.k8s.io.")},
    37  			expected: true,
    38  		},
    39  		{
    40  			rrs:      &route53.ResourceRecordSet{Type: aws.String("A"), Name: aws.String("etcd-b.internal.e2e-61246-dba53.test-cncf-aws.k8s.io.")},
    41  			expected: true,
    42  		},
    43  		{
    44  			rrs:      &route53.ResourceRecordSet{Type: aws.String("A"), Name: aws.String("etcd-events-b.internal.e2e-61246-dba53.test-cncf-aws.k8s.io.")},
    45  			expected: true,
    46  		},
    47  		{
    48  			// Ignores non-A records
    49  			rrs:      &route53.ResourceRecordSet{Type: aws.String("CNAME"), Name: aws.String("api.e2e-61246-dba53.test-cncf-aws.k8s.io.")},
    50  			expected: false,
    51  		},
    52  		{
    53  			// Must ignore the hosted zone system records
    54  			rrs:      &route53.ResourceRecordSet{Type: aws.String("NS"), Name: aws.String("test-cncf-aws.k8s.io.")},
    55  			expected: false,
    56  		},
    57  		{
    58  			// Must ignore the hosted zone system records
    59  			rrs:      &route53.ResourceRecordSet{Type: aws.String("SOA"), Name: aws.String("test-cncf-aws.k8s.io.")},
    60  			expected: false,
    61  		},
    62  		{
    63  			// Ignore names that are from tests that reuse cluster names
    64  			rrs:      &route53.ResourceRecordSet{Type: aws.String("A"), Name: aws.String("api.e2e-e2e-kops-aws.test-cncf-aws.k8s.io.")},
    65  			expected: false,
    66  		},
    67  		{
    68  			// Ignore arbitrary name
    69  			rrs:      &route53.ResourceRecordSet{Type: aws.String("A"), Name: aws.String("website.test-cncf-aws.k8s.io.")},
    70  			expected: false,
    71  		},
    72  	}
    73  	for _, g := range grid {
    74  		actual := resourceRecordSetIsManaged(g.rrs)
    75  		if actual != g.expected {
    76  			t.Errorf("resource record %+v expected=%t actual=%t", g.rrs, g.expected, actual)
    77  		}
    78  	}
    79  }