...
1 package syncedobject
2
3 import (
4 "encoding/base64"
5 "testing"
6
7 "github.com/google/uuid"
8 "github.com/stretchr/testify/require"
9
10 soapi "edge-infra.dev/pkg/edge/apis/syncedobject/apis/v1alpha1"
11 )
12
13 func TestIsStorageLocationOutdated(t *testing.T) {
14 var goodDir = "foo"
15 var goodObjectStr = "apiVersion: v1\nkind: Foo\nmetadata:\n name: foo\n"
16 var good = soapi.SyncedObject{
17 Spec: soapi.SyncedObjectSpec{
18 Banner: "ret-edge-storage-location",
19 Cluster: uuid.New().String(),
20 Directory: &goodDir,
21 Object: base64.StdEncoding.EncodeToString([]byte(goodObjectStr)),
22 },
23 }
24
25
26 var so = good
27 x, err := IsStorageLocationOutdated(&so)
28 require.NoError(t, err)
29 require.False(t, x)
30
31
32 require.NoError(t, good.SetStatusDetails())
33 x, err = IsStorageLocationOutdated(&so)
34 require.NoError(t, err)
35 require.False(t, x)
36
37
38 so = good
39 so.Spec.Banner = "ret-edge-updated"
40 x, err = IsStorageLocationOutdated(&so)
41 require.NoError(t, err)
42 require.True(t, x)
43
44
45 so = good
46 so.Spec.Cluster = ""
47 x, err = IsStorageLocationOutdated(&so)
48 require.NoError(t, err)
49 require.True(t, x)
50
51 so.Spec.Cluster = uuid.New().String()
52 x, err = IsStorageLocationOutdated(&so)
53 require.NoError(t, err)
54 require.True(t, x)
55
56
57 so = good
58 so.Spec.Directory = nil
59 x, err = IsStorageLocationOutdated(&so)
60 require.NoError(t, err)
61 require.True(t, x)
62
63 var barDir = "bar"
64 so.Spec.Directory = &barDir
65 x, err = IsStorageLocationOutdated(&so)
66 require.NoError(t, err)
67 require.True(t, x)
68
69
70 so = good
71 so.Spec.Object = base64.StdEncoding.EncodeToString([]byte(goodObjectStr + " namespace: foo\n"))
72 x, err = IsStorageLocationOutdated(&so)
73 require.NoError(t, err)
74 require.True(t, x)
75
76
77 so.Spec.Object = base64.StdEncoding.EncodeToString([]byte(goodObjectStr + "spec:\n ignored: foo\n"))
78 x, err = IsStorageLocationOutdated(&so)
79 require.NoError(t, err)
80 require.False(t, x)
81 }
82
View as plain text