You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: endpointslice_tracker_test.go
    path of file: ./repos/kubernetes/staging/src/k8s.io/endpointslice/util
    
    the code of the file until where you have to start completion: /*
Copyright 2019 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 util

import (
	"testing"

	v1 "k8s.io/api/core/v1"
	discovery "k8s.io/api/discovery/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/types"
)

func TestEndpointSliceTrackerUpdate(t *testing.T) {
	epSlice1 := &discovery.EndpointSlice{
		ObjectMeta: metav1.ObjectMeta{
			Name:       "example-1",
			Namespace:  "ns1",
			UID:        "original",
			Generation: 1,
			Labels:     map[string]string{discovery.LabelServiceName: "svc1"},
		},
	}

	epSlice1DifferentNS := epSlice1.DeepCopy()
	epSlice1DifferentNS.Namespace = "ns2"
	epSlice1DifferentNS.UID = "diff-ns"

	epSlice1DifferentService := epSlice1.DeepCopy()
	epSlice1DifferentService.Labels[discovery.LabelServiceName] = "svc2"
	epSlice1DifferentService.UID = "diff-svc"

	epSlice1NewerGen := epSlice1.DeepCopy()
	epSlice1NewerGen.Generation = 2

	testCases := map[string]struct {
		updateParam      *discovery.EndpointSlice
		checksParam      *discovery.EndpointSlice
		expectHas        bool
		expectShouldSync bool
		expectGeneration int64
	}{
		"same slice": {
			updateParam:      epSlice1,
			checksParam:      epSlice1,
			expectHas:        true,
			expectShouldSync: false,
			expectGeneration: epSlice1.Generation,
		},
		"different namespace": {
			updateParam:      epSlice1,
			checksParam:      epSlice1DifferentNS,
			expectHas:        false,
			expectShouldSync: true,
			expectGeneration: epSlice1.Generation,
		},
		"different service": {
			updateParam:      epSlice1,
			checksParam:      epSlice1DifferentService,
			expectHas:        false,
			expectShouldSync: true,
			expectGeneration: epSlice1.Generation,
		},
		"newer generation": {
			updateParam:      epSlice1,
			checksParam:      epSlice1NewerGen,
			expectHas:        true,
			expectShouldSync: true,
			expectGeneration: epSlice1.Generation,
		},
	}

	for name, tc := range testCases {
		t.Run(name, func(t *testing.T) {
			esTracker := NewEndpointSliceTracker()
			esTracker.Update(tc.updateParam)
			if esTracker.Has(tc.checksParam) != tc.expectHas {
				t.Errorf("tc.tracker.Has(%+v) == %t, expected %t", tc.checksParam, esTracker.Has(tc.checksParam), tc.expectHas)
			}
			if esTracker.ShouldSync(tc.checksParam) != tc.expectShouldSync {
				t.Errorf("tc.tracker.ShouldSync(%+v) == %t, expected %t", tc.checksParam, esTracker.ShouldSync(tc.checksParam), tc.expectShouldSync)
			}
			serviceNN := types.NamespacedName{Namespace: epSlice1.Namespace, Name: "svc1"}
			gfs, ok := esTracker.generationsByService[serviceNN]
			if !ok {
				t.Fatalf("expected tracker to have generations for %s Service", serviceNN.Name)
			}
			generation, ok := gfs[epSlice1.UID]
			if !ok {
				t.Fatalf("expected tracker to have generation for %s EndpointSlice", epSlice1.Name)
			}
			if tc.expectGeneration != generation {
				t.Fatalf("expected generation to b
    
func TestEndpointSliceTrackerStaleSlices(t *testing.T) {
	epSlice1 := &discovery.EndpointSlice{
		ObjectMeta: metav1.ObjectMeta{
			Name:       "example-1",
			Namespace:  "ns1",
			UID:        "original",
			Generation: 1,
			Labels:     map[string]string{discovery.LabelServiceName: "svc1"},
		},
	}

	epSlice1NewerGen := epSlice1.DeepCopy()
	epSlice1NewerGen.Generation = 2

	epTerminatingSlice := epSlice1.DeepCopy()
	now := metav1.Now()
	epTerminatingSlice.DeletionTimestamp = &now

	testCases := []struct {
		name         string
		tracker      *EndpointSliceTracker
		serviceParam *v1.Service
		slicesParam  []*discovery.EndpointSlice
		expectNewer  bool
	}{{
		name: "empty tracker",
		tracker: &EndpointSliceTracker{
			generationsByService: map[types.NamespacedName]GenerationsBySlice{},
		},
		serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}},
		slicesParam:  []*discovery.EndpointSlice{},
		expectNewer:  false,
	}, {
		name: "empty slices",
		tracker: &EndpointSliceTracker{
			generationsByService: map[types.NamespacedName]GenerationsBySlice{
				{Name: "svc1", Namespace: "ns1"}: {},
			},
		},
		serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}},
		slicesParam:  []*discovery.EndpointSlice{},
		expectNewer:  false,
	}, {
		name: "matching slices",
		tracker: &EndpointSliceTracker{
			generationsByService: map[types.NamespacedName]GenerationsBySlice{
				{Name: "svc1", Namespace: "ns1"}: {
					epSlice1.UID: epSlice1.Generation,
				},
			},
		},
		serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}},
		slicesParam:  []*discovery.EndpointSlice{epSlice1},
		expectNewer:  false,
	}, {
		name: "newer slice in tracker",
		tracker: &EndpointSliceTracker{
			generationsByService: map[types.NamespacedName]GenerationsBySlice{
				{Name: "svc1", Namespace: "ns1"}: {
					epSlice1.UID: epSlice1NewerGen.Generation,
				},
			},
		},
		serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}},
		slicesParam:  []*discovery.EndpointSlice{epSlice1},
		expectNewer:  true,
	}, {
		name: "newer slice in params",
		tracker: &EndpointSliceTracker{
			generationsByService: map[types.NamespacedName]GenerationsBySlice{
				{Name: "svc1", Namespace: "ns1"}: {
					epSlice1.UID: epSlice1.Generation,
				},
			},
		},
		serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}},
		slicesParam:  []*discovery.EndpointSlice{epSlice1NewerGen},
		expectNewer:  false,
	}, {
		name: "slice in params is expected to be deleted",
		tracker: &EndpointSliceTracker{
			generationsByService: map[types.NamespacedName]GenerationsBySlice{
				{Name: "svc1", Namespace: "ns1"}: {
					epSlice1.UID: deletionExpected,
				},
			},
		},
		serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}},
		slicesParam:  []*discovery.EndpointSlice{epSlice1},
		expectNewer:  true,
	}, {
		name: "slice in tracker but not in params",
		tracker: &EndpointSliceTracker{
			generationsByService: map[types.NamespacedName]GenerationsBySlice{
				{Name: "svc1", Namespace: "ns1"}: {
					epSlice1.UID: epSlice1.Generation,
				},
			},
		},
		serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}},
		slicesParam:  []*discovery.EndpointSlice{},
		expectNewer:  true,
	}}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			actualNewer := tc.tracker.StaleSlices(tc.serviceParam, tc.slicesParam)
			if actualNewer != tc.expectNewer {
				t.Errorf("Expected %t, got %t", tc.expectNewer, actualNewer)
			}
		})
	}
}