Unrelated Pod Information (#171)
* unrelated pod information * added test case for payloads with same prefix
This commit is contained in:
Родитель
e86b222155
Коммит
782fbebe56
|
@ -182,3 +182,33 @@ func Test_removeDupePayloads_twoTheSame_returnsFirstOne(t *testing.T) {
|
|||
ret := removeDupePayloads(input)
|
||||
assert.Equal(t, expected, ret)
|
||||
}
|
||||
|
||||
func Test_GetResPayload_True_HasSamePrefix(t *testing.T) {
|
||||
untyped.TestHookSetPartitionDuration(time.Hour)
|
||||
partitionId := untyped.GetPartitionId(someTs)
|
||||
values := helper_get_params()
|
||||
expectedKind := "someKind"
|
||||
expectedNS := "someNamespace"
|
||||
expectedName := "someName-11"
|
||||
values[KindParam] = []string{expectedKind}
|
||||
values[NamespaceParam] = []string{expectedNS}
|
||||
values[NameParam] = []string{expectedName}
|
||||
|
||||
var keys []string
|
||||
keys = append(keys, typed.NewWatchTableKey(partitionId, expectedKind, expectedNS, expectedName, someTs).String())
|
||||
keys = append(keys, typed.NewWatchTableKey(partitionId, "someKind", "someNamespace", "someName-1", someTs).String())
|
||||
keys = append(keys, typed.NewWatchTableKey(partitionId, "someKind", "someNamespace", "someName-16", someTs).String())
|
||||
keys = append(keys, typed.NewWatchTableKey(partitionId, "someKind", "someNamespace", "someName-15", someTs).String())
|
||||
|
||||
tables := helper_get_resPayload(keys, t, somePTime)
|
||||
res, err := GetResPayload(values, tables, someTs.Add(-1*time.Hour), someTs.Add(6*time.Hour), someRequestId)
|
||||
assert.Nil(t, err)
|
||||
expectedRes := `[
|
||||
{
|
||||
"payloadTime": 1546398245000000006,
|
||||
"payload": "{\n \"metadata\": {\n \"name\": \"someName\",\n \"namespace\": \"someNamespace\",\n \"uid\": \"6c2a9795-a282-11e9-ba2f-14187761de09\",\n \"creationTimestamp\": \"2019-07-09T19:47:45Z\"\n }\n}",
|
||||
"payloadKey": "/watch/001546398000/someKind/someNamespace/someName-11/1546398245000000006"
|
||||
}
|
||||
]`
|
||||
assertex.JsonEqual(t, expectedRes, string(res))
|
||||
}
|
||||
|
|
|
@ -71,9 +71,9 @@ func (k *WatchTableKey) SetPartitionId(newPartitionId string) {
|
|||
//todo: need to make sure it can work as keyPrefix when some fields are empty
|
||||
func (k *WatchTableKey) String() string {
|
||||
if k.Name == "" && k.Timestamp.IsZero() {
|
||||
return fmt.Sprintf("/%v/%v/%v/%v", k.TableName(), k.PartitionId, k.Kind, k.Namespace)
|
||||
return fmt.Sprintf("/%v/%v/%v/%v/", k.TableName(), k.PartitionId, k.Kind, k.Namespace)
|
||||
} else if k.Timestamp.IsZero() {
|
||||
return fmt.Sprintf("/%v/%v/%v/%v/%v", k.TableName(), k.PartitionId, k.Kind, k.Namespace, k.Name)
|
||||
return fmt.Sprintf("/%v/%v/%v/%v/%v/", k.TableName(), k.PartitionId, k.Kind, k.Namespace, k.Name)
|
||||
} else {
|
||||
return fmt.Sprintf("/%v/%v/%v/%v/%v/%v", k.TableName(), k.PartitionId, k.Kind, k.Namespace, k.Name, k.Timestamp.UnixNano())
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче