mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Unified Storage: Fix Compare method (#90455)
* Unified Storage: Fix Compare method Signed-off-by: Maicon Costa <maiconscosta@gmail.com> --------- Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
This commit is contained in:
parent
1c031277af
commit
93221f12da
@ -241,7 +241,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")
|
||||||
|
|
||||||
jsonObj, err := json.Marshal(cpy)
|
jsonObj, err := json.Marshal(unstObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,11 @@ import (
|
|||||||
"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"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
|
// nolint:depguard
|
||||||
|
playlist "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetDualWritingMode(t *testing.T) {
|
func TestSetDualWritingMode(t *testing.T) {
|
||||||
@ -59,24 +63,44 @@ 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 examplePlaylistGen2 = &playlist.Playlist{ObjectMeta: metav1.ObjectMeta{Generation: 2}, Spec: playlist.Spec{Title: "Example Playlist"}}
|
||||||
|
var anotherPlaylist = &playlist.Playlist{ObjectMeta: metav1.ObjectMeta{Generation: 2}, Spec: playlist.Spec{Title: "Another Playlist"}}
|
||||||
|
|
||||||
testCase := []struct {
|
testCase := []struct {
|
||||||
name string
|
name string
|
||||||
input runtime.Object
|
input1 runtime.Object
|
||||||
|
input2 runtime.Object
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "should return true when both objects are the same",
|
name: "should return true when both objects are the same",
|
||||||
input: exampleObj,
|
input1: exampleObj,
|
||||||
|
input2: exampleObj,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "should return false when objects are different",
|
name: "should return false when objects are different",
|
||||||
input: anotherObj,
|
input1: exampleObj,
|
||||||
|
input2: anotherObj,
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "should return true when Playlists are the same, but different metadata (generation)",
|
||||||
|
input1: examplePlaylistGen1,
|
||||||
|
input2: examplePlaylistGen2,
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "should return false when Playlists different",
|
||||||
|
input1: examplePlaylistGen1,
|
||||||
|
input2: anotherPlaylist,
|
||||||
|
expected: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range testCase {
|
for _, tt := range testCase {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
assert.Equal(t, tt.expected, Compare(tt.input, exampleObj))
|
assert.Equal(t, tt.expected, Compare(tt.input1, tt.input2))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user