@@ -17,8 +17,6 @@ limitations under the License.
1717package meta
1818
1919import (
20- "fmt"
21- "hash/fnv"
2220 "testing"
2321 "time"
2422
@@ -1181,147 +1179,6 @@ func TestExternalCreateIncomplete(t *testing.T) {
11811179 }
11821180}
11831181
1184- func TestAllowPropagation (t * testing.T ) {
1185- fromns := "from-namespace"
1186- from := "from-name"
1187- tons := "to-namespace"
1188- to := "to-name"
1189-
1190- tohash := func () string {
1191- h := fnv .New32a ()
1192- h .Write ([]byte (tons ))
1193- h .Write ([]byte (to ))
1194- return fmt .Sprintf ("%x" , h .Sum32 ())
1195- }()
1196-
1197- type args struct {
1198- from metav1.Object
1199- to metav1.Object
1200- }
1201- type want struct {
1202- from metav1.Object
1203- to metav1.Object
1204- }
1205-
1206- cases := map [string ]struct {
1207- args args
1208- want want
1209- }{
1210- "Successful" : {
1211- args : args {
1212- from : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
1213- Namespace : fromns ,
1214- Name : from ,
1215- Annotations : map [string ]string {
1216- "existing" : "annotation" ,
1217- },
1218- }},
1219- to : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
1220- Namespace : tons ,
1221- Name : to ,
1222- Annotations : map [string ]string {
1223- "existing" : "annotation" ,
1224- },
1225- }},
1226- },
1227- want : want {
1228- from : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
1229- Namespace : fromns ,
1230- Name : from ,
1231- Annotations : map [string ]string {
1232- "existing" : "annotation" ,
1233- AnnotationKeyPropagateToPrefix + tohash : tons + "/" + to ,
1234- },
1235- }},
1236- to : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
1237- Namespace : tons ,
1238- Name : to ,
1239- Annotations : map [string ]string {
1240- "existing" : "annotation" ,
1241- AnnotationKeyPropagateFromNamespace : fromns ,
1242- AnnotationKeyPropagateFromName : from ,
1243- },
1244- }},
1245- },
1246- },
1247- }
1248-
1249- for name , tc := range cases {
1250- t .Run (name , func (t * testing.T ) {
1251- AllowPropagation (tc .args .from , tc .args .to )
1252- if diff := cmp .Diff (tc .want .from , tc .args .from ); diff != "" {
1253- t .Errorf ("AllowPropagation(...): -want from, +got from\n %s" , diff )
1254- }
1255- if diff := cmp .Diff (tc .want .to , tc .args .to ); diff != "" {
1256- t .Errorf ("AllowPropagation(...): -want to, +got to\n %s" , diff )
1257- }
1258- })
1259- }
1260- }
1261-
1262- func TestAllowsPropagationFrom (t * testing.T ) {
1263- ns := "coolns"
1264- name := "coolname"
1265-
1266- cases := map [string ]struct {
1267- to metav1.Object
1268- want types.NamespacedName
1269- }{
1270- "Successful" : {
1271- to : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Annotations : map [string ]string {
1272- AnnotationKeyPropagateFromNamespace : ns ,
1273- AnnotationKeyPropagateFromName : name ,
1274- }}},
1275- want : types.NamespacedName {Namespace : ns , Name : name },
1276- },
1277- }
1278-
1279- for name , tc := range cases {
1280- t .Run (name , func (t * testing.T ) {
1281- got := AllowsPropagationFrom (tc .to )
1282- if diff := cmp .Diff (tc .want , got ); diff != "" {
1283- t .Errorf ("AllowsPropagationFrom(...): -want, +got\n %s" , diff )
1284- }
1285- })
1286- }
1287- }
1288-
1289- func TestAllowsPropagationTo (t * testing.T ) {
1290- nsA := "coolns"
1291- nameA := "coolname"
1292- nsB := "coolerns"
1293- nameB := "coolername"
1294-
1295- cases := map [string ]struct {
1296- from metav1.Object
1297- want map [types.NamespacedName ]bool
1298- }{
1299- "Successful" : {
1300- from : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Annotations : map [string ]string {
1301- "existing" : "annotation" ,
1302- AnnotationKeyPropagateToPrefix + "missingslash" : "wat" ,
1303- AnnotationKeyPropagateToPrefix + "missingname" : "wat/" ,
1304- AnnotationKeyPropagateToPrefix + "missingnamespace" : "/wat" ,
1305- AnnotationKeyPropagateToPrefix + "a" : nsA + "/" + nameA ,
1306- AnnotationKeyPropagateToPrefix + "b" : nsB + "/" + nameB ,
1307- }}},
1308- want : map [types.NamespacedName ]bool {
1309- {Namespace : nsA , Name : nameA }: true ,
1310- {Namespace : nsB , Name : nameB }: true ,
1311- },
1312- },
1313- }
1314-
1315- for name , tc := range cases {
1316- t .Run (name , func (t * testing.T ) {
1317- got := AllowsPropagationTo (tc .from )
1318- if diff := cmp .Diff (tc .want , got ); diff != "" {
1319- t .Errorf ("AllowsPropagationTo(...): -want, +got\n %s" , diff )
1320- }
1321- })
1322- }
1323- }
1324-
13251182func TestIsPaused (t * testing.T ) {
13261183 cases := map [string ]struct {
13271184 o metav1.Object
0 commit comments