Chore: Remove depguard rule skip in apiserver (#91705)

This commit is contained in:
Todd Treece 2024-08-08 14:11:13 -04:00 committed by GitHub
parent 299c142f6a
commit f463d622d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 18 deletions

View File

@ -240,6 +240,7 @@ func removeMeta(obj runtime.Object) []byte {
} }
// we don't want to compare meta fields // we don't want to compare meta fields
delete(unstObj, "metadata") delete(unstObj, "metadata")
delete(unstObj, "objectMeta")
jsonObj, err := json.Marshal(unstObj) jsonObj, err := json.Marshal(unstObj)
if err != nil { if err != nil {

View File

@ -4,15 +4,14 @@ import (
"context" "context"
"fmt" "fmt"
"testing" "testing"
"time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/apis/example"
// nolint:depguard
playlist "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
) )
func TestSetDualWritingMode(t *testing.T) { func TestSetDualWritingMode(t *testing.T) {
@ -63,9 +62,9 @@ func TestSetDualWritingMode(t *testing.T) {
} }
func TestCompare(t *testing.T) { func TestCompare(t *testing.T) {
var examplePlaylistGen1 = &playlist.Playlist{ObjectMeta: metav1.ObjectMeta{Generation: 1}, Spec: playlist.Spec{Title: "Example Playlist"}} var exampleObjGen1 = &example.Pod{ObjectMeta: metav1.ObjectMeta{Generation: 1}, Spec: example.PodSpec{Hostname: "one"}, Status: example.PodStatus{StartTime: &metav1.Time{Time: time.Unix(0, 0)}}}
var examplePlaylistGen2 = &playlist.Playlist{ObjectMeta: metav1.ObjectMeta{Generation: 2}, Spec: playlist.Spec{Title: "Example Playlist"}} var exampleObjGen2 = &example.Pod{ObjectMeta: metav1.ObjectMeta{Generation: 2}, Spec: example.PodSpec{Hostname: "one"}, Status: example.PodStatus{StartTime: &metav1.Time{Time: time.Unix(0, 0)}}}
var anotherPlaylist = &playlist.Playlist{ObjectMeta: metav1.ObjectMeta{Generation: 2}, Spec: playlist.Spec{Title: "Another Playlist"}} var exampleObjDifferentTitle = &example.Pod{ObjectMeta: metav1.ObjectMeta{Generation: 2}, Spec: example.PodSpec{Hostname: "two"}, Status: example.PodStatus{StartTime: &metav1.Time{Time: time.Unix(0, 0)}}}
testCase := []struct { testCase := []struct {
name string name string
@ -80,21 +79,15 @@ func TestCompare(t *testing.T) {
expected: true, expected: true,
}, },
{ {
name: "should return false when objects are different", name: "should return true when objects are the same, but different metadata (generation)",
input1: exampleObj, input1: exampleObjGen1,
input2: anotherObj, input2: exampleObjGen2,
expected: false,
},
{
name: "should return true when Playlists are the same, but different metadata (generation)",
input1: examplePlaylistGen1,
input2: examplePlaylistGen2,
expected: true, expected: true,
}, },
{ {
name: "should return false when Playlists different", name: "should return false when objects are different",
input1: examplePlaylistGen1, input1: exampleObjGen1,
input2: anotherPlaylist, input2: exampleObjDifferentTitle,
expected: false, expected: false,
}, },
} }