From c38045a43d8e4b07b0b67a2f09d7352d25f9ebe8 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 23 Apr 2017 22:01:54 +0000 Subject: [PATCH] Add check on generated msgpack --- report/marshal_test.go | 182 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/report/marshal_test.go b/report/marshal_test.go index 2c7bbe3a2..771b5e8b5 100644 --- a/report/marshal_test.go +++ b/report/marshal_test.go @@ -138,6 +138,22 @@ func TestMoreCompressionMeansSmaller(t *testing.T) { } } +func TestEncodeMsgpackBackwardsCompat(t *testing.T) { + var buf bytes.Buffer + r1 := makeTestReport() + if err := codec.NewEncoder(&buf, &codec.MsgpackHandle{}).Encode(&r1); err != nil { + t.Error(err) + } + buf1 := buf.Bytes() + buf2 := msgpack_1_2xx + if len(buf1) != len(buf2) { + t.Errorf("Length of encoded data is wrong: %v != %v", len(buf1), len(buf2)) + } + if !reflect.DeepEqual(buf1, buf2) { + t.Errorf("%v != %v", buf1, buf2) + } +} + // First sample taken from code checked out at v1.1 tag and then output hand-altered to match fixed timestamps var json_v1_1 []byte = []byte(`{"Endpoint":{"nodes":{";172.20.1.168;41582":{"id":";172.20.1.168;41582","topology":"endpoint","counters":{},"sets":{"snooped_dns_names":["ip-172-20-1-168.ec2.internal"]},"adjacency":[";54.84.140.34;443"],"edges":{";54.84.140.34;443":{}},"controls":{"timestamp":"2016-12-25T07:37:00Z","controls":["docker_remove_container"]},"latestControls":{"docker_pause_container":{"timestamp":"2016-12-25T07:37:00Z","value":{"dead":false}}},"latest":{"addr":{"timestamp":"2016-12-25T07:36:00Z","value":"127.0.0.1"}},"parents":{},"children":null}}},"Process":{"shape":"square","label":"process","label_plural":"processes","nodes":{"ip-172-20-1-168;10446":{"id":"ip-172-20-1-168;10446","topology":"process","counters":{},"sets":{},"adjacency":null,"edges":{},"controls":{},"latestControls":{},"latest":{"pid":{"timestamp":"2016-12-25T07:36:00Z","value":"10446"}},"metrics":{"process_cpu_usage_percent":{"samples":[{"date":"2016-12-25T07:36:00Z","value":1E-01},{"date":"2016-12-25T07:36:01Z","value":2E-01}],"min":1E-01,"max":2E-01,"first":"2016-12-25T07:36:00Z","last":"2016-12-25T07:36:01Z"}},"parents":{"host":["ip-172-20-1-168;\u003chost\u003e"]},"children":null}}},"Container":{"shape":"hexagon","label":"container","label_plural":"containers","nodes":{}},"Pod":{"shape":"heptagon","label":"pod","label_plural":"pods","nodes":{"fceef9592ec3cf1a8e1d178fdd0de41a;\u003cpod\u003e":{"id":"fceef9592ec3cf1a8e1d178fdd0de41a;\u003cpod\u003e","topology":"pod","counters":{},"sets":{},"adjacency":null,"edges":{},"controls":{"timestamp":"2016-12-25T07:37:00Z","controls":["kubernetes_delete_pod"]},"latestControls":{"kubernetes_get_logs":{"timestamp":"2016-12-25T07:37:00Z","value":{"dead":true}}},"latest":{"host_node_id":{"timestamp":"2016-12-25T07:36:00Z","value":"ip-172-20-1-168;\u003chost\u003e"}},"parents":{},"children":null}}},"Service":{"shape":"heptagon","label":"service","label_plural":"services","nodes":{}},"Deployment":{"shape":"heptagon","label":"deployment","label_plural":"deployments","nodes":{}},"ReplicaSet":{"shape":"heptagon","label":"replica set","label_plural":"replica sets","nodes":{}},"ContainerImage":{"shape":"hexagon","label":"image","label_plural":"images","nodes":{}},"Host":{"shape":"circle","label":"host","label_plural":"hosts","nodes":{}},"ECSTask":{"shape":"heptagon","label":"task","label_plural":"tasks","nodes":{}},"ECSService":{"shape":"heptagon","label":"service","label_plural":"services","nodes":{}},"Overlay":{"shape":"circle","label":"peer","label_plural":"peers","nodes":{"#docker_peer_ip-172-20-1-168":{"id":"#docker_peer_ip-172-20-1-168","topology":"overlay","counters":{},"sets":{"local_networks":["172.18.0.0/16"]},"adjacency":null,"edges":{},"controls":{},"latestControls":{},"latest":{},"parents":{},"children":null}},"metadata_templates":{"weave_encryption":{"id":"weave_encryption","label":"Encryption","priority":4E+00,"from":"latest"}}},"Sampling":{"Count":0,"Total":0},"Window":0,"Shortcut":false,"Plugins":[],"ID":"3894069658342253419"}`) @@ -644,3 +660,169 @@ var msgpack_1_2x = []byte{222, 0, 17, 168, 69, 110, 100, 112, 111, 105, 167, 80, 108, 117, 103, 105, 110, 115, 144, 162, 73, 68, 179, 51, 56, 57, 52, 48, 54, 57, 54, 53, 56, 51, 52, 50, 50, 53, 51, 52, 49, 57} + +// Generated from git hash c944225475660ccf84e54635d2833910aefa9446 +var msgpack_1_2xx = []byte{222, 0, 18, 168, 69, 110, 100, 112, 111, 105, + 110, 116, 129, 165, 110, 111, 100, 101, 115, 129, 179, 59, 49, 55, 50, + 46, 50, 48, 46, 49, 46, 49, 54, 56, 59, 52, 49, 53, 56, 50, 139, 162, + 105, 100, 179, 59, 49, 55, 50, 46, 50, 48, 46, 49, 46, 49, 54, 56, 59, + 52, 49, 53, 56, 50, 168, 116, 111, 112, 111, 108, 111, 103, 121, 168, + 101, 110, 100, 112, 111, 105, 110, 116, 168, 99, 111, 117, 110, 116, + 101, 114, 115, 128, 164, 115, 101, 116, 115, 129, 177, 115, 110, 111, + 111, 112, 101, 100, 95, 100, 110, 115, 95, 110, 97, 109, 101, 115, + 145, 188, 105, 112, 45, 49, 55, 50, 45, 50, 48, 45, 49, 45, 49, 54, + 56, 46, 101, 99, 50, 46, 105, 110, 116, 101, 114, 110, 97, 108, 169, + 97, 100, 106, 97, 99, 101, 110, 99, 121, 145, 177, 59, 53, 52, 46, 56, + 52, 46, 49, 52, 48, 46, 51, 52, 59, 52, 52, 51, 165, 101, 100, 103, + 101, 115, 129, 177, 59, 53, 52, 46, 56, 52, 46, 49, 52, 48, 46, 51, + 52, 59, 52, 52, 51, 128, 168, 99, 111, 110, 116, 114, 111, 108, 115, + 130, 169, 116, 105, 109, 101, 115, 116, 97, 109, 112, 180, 50, 48, 49, + 54, 45, 49, 50, 45, 50, 53, 84, 48, 55, 58, 51, 55, 58, 48, 48, 90, + 168, 99, 111, 110, 116, 114, 111, 108, 115, 145, 183, 100, 111, 99, + 107, 101, 114, 95, 114, 101, 109, 111, 118, 101, 95, 99, 111, 110, + 116, 97, 105, 110, 101, 114, 174, 108, 97, 116, 101, 115, 116, 67, + 111, 110, 116, 114, 111, 108, 115, 129, 182, 100, 111, 99, 107, 101, + 114, 95, 112, 97, 117, 115, 101, 95, 99, 111, 110, 116, 97, 105, 110, + 101, 114, 130, 169, 116, 105, 109, 101, 115, 116, 97, 109, 112, 175, + 1, 0, 0, 0, 14, 207, 241, 110, 28, 0, 0, 0, 0, 255, 255, 165, 118, 97, + 108, 117, 101, 129, 164, 100, 101, 97, 100, 194, 166, 108, 97, 116, + 101, 115, 116, 129, 164, 97, 100, 100, 114, 130, 169, 116, 105, 109, + 101, 115, 116, 97, 109, 112, 175, 1, 0, 0, 0, 14, 207, 241, 109, 224, + 0, 0, 0, 0, 255, 255, 165, 118, 97, 108, 117, 101, 169, 49, 50, 55, + 46, 48, 46, 48, 46, 49, 167, 112, 97, 114, 101, 110, 116, 115, 128, + 168, 99, 104, 105, 108, 100, 114, 101, 110, 192, 167, 80, 114, 111, + 99, 101, 115, 115, 132, 165, 115, 104, 97, 112, 101, 166, 115, 113, + 117, 97, 114, 101, 165, 108, 97, 98, 101, 108, 167, 112, 114, 111, 99, + 101, 115, 115, 172, 108, 97, 98, 101, 108, 95, 112, 108, 117, 114, 97, + 108, 169, 112, 114, 111, 99, 101, 115, 115, 101, 115, 165, 110, 111, + 100, 101, 115, 129, 181, 105, 112, 45, 49, 55, 50, 45, 50, 48, 45, 49, + 45, 49, 54, 56, 59, 49, 48, 52, 52, 54, 140, 162, 105, 100, 181, 105, + 112, 45, 49, 55, 50, 45, 50, 48, 45, 49, 45, 49, 54, 56, 59, 49, 48, + 52, 52, 54, 168, 116, 111, 112, 111, 108, 111, 103, 121, 167, 112, + 114, 111, 99, 101, 115, 115, 168, 99, 111, 117, 110, 116, 101, 114, + 115, 128, 164, 115, 101, 116, 115, 128, 169, 97, 100, 106, 97, 99, + 101, 110, 99, 121, 192, 165, 101, 100, 103, 101, 115, 128, 168, 99, + 111, 110, 116, 114, 111, 108, 115, 128, 174, 108, 97, 116, 101, 115, + 116, 67, 111, 110, 116, 114, 111, 108, 115, 128, 166, 108, 97, 116, + 101, 115, 116, 129, 163, 112, 105, 100, 130, 169, 116, 105, 109, 101, + 115, 116, 97, 109, 112, 175, 1, 0, 0, 0, 14, 207, 241, 109, 224, 0, 0, + 0, 0, 255, 255, 165, 118, 97, 108, 117, 101, 165, 49, 48, 52, 52, 54, + 167, 109, 101, 116, 114, 105, 99, 115, 129, 185, 112, 114, 111, 99, + 101, 115, 115, 95, 99, 112, 117, 95, 117, 115, 97, 103, 101, 95, 112, + 101, 114, 99, 101, 110, 116, 133, 167, 115, 97, 109, 112, 108, 101, + 115, 146, 130, 164, 100, 97, 116, 101, 175, 1, 0, 0, 0, 14, 207, 241, + 109, 224, 0, 0, 0, 0, 255, 255, 165, 118, 97, 108, 117, 101, 203, 63, + 185, 153, 153, 153, 153, 153, 154, 130, 164, 100, 97, 116, 101, 175, + 1, 0, 0, 0, 14, 207, 241, 109, 225, 0, 0, 0, 0, 255, 255, 165, 118, + 97, 108, 117, 101, 203, 63, 201, 153, 153, 153, 153, 153, 154, 163, + 109, 105, 110, 203, 63, 185, 153, 153, 153, 153, 153, 154, 163, 109, + 97, 120, 203, 63, 201, 153, 153, 153, 153, 153, 154, 165, 102, 105, + 114, 115, 116, 180, 50, 48, 49, 54, 45, 49, 50, 45, 50, 53, 84, 48, + 55, 58, 51, 54, 58, 48, 48, 90, 164, 108, 97, 115, 116, 180, 50, 48, + 49, 54, 45, 49, 50, 45, 50, 53, 84, 48, 55, 58, 51, 54, 58, 48, 49, + 90, 167, 112, 97, 114, 101, 110, 116, 115, 129, 164, 104, 111, 115, + 116, 145, 182, 105, 112, 45, 49, 55, 50, 45, 50, 48, 45, 49, 45, 49, + 54, 56, 59, 60, 104, 111, 115, 116, 62, 168, 99, 104, 105, 108, 100, + 114, 101, 110, 192, 169, 67, 111, 110, 116, 97, 105, 110, 101, 114, + 132, 165, 115, 104, 97, 112, 101, 167, 104, 101, 120, 97, 103, 111, + 110, 165, 108, 97, 98, 101, 108, 169, 99, 111, 110, 116, 97, 105, 110, + 101, 114, 172, 108, 97, 98, 101, 108, 95, 112, 108, 117, 114, 97, 108, + 170, 99, 111, 110, 116, 97, 105, 110, 101, 114, 115, 165, 110, 111, + 100, 101, 115, 128, 163, 80, 111, 100, 132, 165, 115, 104, 97, 112, + 101, 168, 104, 101, 112, 116, 97, 103, 111, 110, 165, 108, 97, 98, + 101, 108, 163, 112, 111, 100, 172, 108, 97, 98, 101, 108, 95, 112, + 108, 117, 114, 97, 108, 164, 112, 111, 100, 115, 165, 110, 111, 100, + 101, 115, 129, 218, 0, 38, 102, 99, 101, 101, 102, 57, 53, 57, 50, + 101, 99, 51, 99, 102, 49, 97, 56, 101, 49, 100, 49, 55, 56, 102, 100, + 100, 48, 100, 101, 52, 49, 97, 59, 60, 112, 111, 100, 62, 139, 162, + 105, 100, 218, 0, 38, 102, 99, 101, 101, 102, 57, 53, 57, 50, 101, 99, + 51, 99, 102, 49, 97, 56, 101, 49, 100, 49, 55, 56, 102, 100, 100, 48, + 100, 101, 52, 49, 97, 59, 60, 112, 111, 100, 62, 168, 116, 111, 112, + 111, 108, 111, 103, 121, 163, 112, 111, 100, 168, 99, 111, 117, 110, + 116, 101, 114, 115, 128, 164, 115, 101, 116, 115, 128, 169, 97, 100, + 106, 97, 99, 101, 110, 99, 121, 192, 165, 101, 100, 103, 101, 115, + 128, 168, 99, 111, 110, 116, 114, 111, 108, 115, 130, 169, 116, 105, + 109, 101, 115, 116, 97, 109, 112, 180, 50, 48, 49, 54, 45, 49, 50, 45, + 50, 53, 84, 48, 55, 58, 51, 55, 58, 48, 48, 90, 168, 99, 111, 110, + 116, 114, 111, 108, 115, 145, 181, 107, 117, 98, 101, 114, 110, 101, + 116, 101, 115, 95, 100, 101, 108, 101, 116, 101, 95, 112, 111, 100, + 174, 108, 97, 116, 101, 115, 116, 67, 111, 110, 116, 114, 111, 108, + 115, 129, 179, 107, 117, 98, 101, 114, 110, 101, 116, 101, 115, 95, + 103, 101, 116, 95, 108, 111, 103, 115, 130, 169, 116, 105, 109, 101, + 115, 116, 97, 109, 112, 175, 1, 0, 0, 0, 14, 207, 241, 110, 28, 0, 0, + 0, 0, 255, 255, 165, 118, 97, 108, 117, 101, 129, 164, 100, 101, 97, + 100, 195, 166, 108, 97, 116, 101, 115, 116, 129, 172, 104, 111, 115, + 116, 95, 110, 111, 100, 101, 95, 105, 100, 130, 169, 116, 105, 109, + 101, 115, 116, 97, 109, 112, 175, 1, 0, 0, 0, 14, 207, 241, 109, 224, + 0, 0, 0, 0, 255, 255, 165, 118, 97, 108, 117, 101, 182, 105, 112, 45, + 49, 55, 50, 45, 50, 48, 45, 49, 45, 49, 54, 56, 59, 60, 104, 111, 115, + 116, 62, 167, 112, 97, 114, 101, 110, 116, 115, 128, 168, 99, 104, + 105, 108, 100, 114, 101, 110, 192, 167, 83, 101, 114, 118, 105, 99, + 101, 132, 165, 115, 104, 97, 112, 101, 168, 104, 101, 112, 116, 97, + 103, 111, 110, 165, 108, 97, 98, 101, 108, 167, 115, 101, 114, 118, + 105, 99, 101, 172, 108, 97, 98, 101, 108, 95, 112, 108, 117, 114, 97, + 108, 168, 115, 101, 114, 118, 105, 99, 101, 115, 165, 110, 111, 100, + 101, 115, 128, 170, 68, 101, 112, 108, 111, 121, 109, 101, 110, 116, + 132, 165, 115, 104, 97, 112, 101, 168, 104, 101, 112, 116, 97, 103, + 111, 110, 165, 108, 97, 98, 101, 108, 170, 100, 101, 112, 108, 111, + 121, 109, 101, 110, 116, 172, 108, 97, 98, 101, 108, 95, 112, 108, + 117, 114, 97, 108, 171, 100, 101, 112, 108, 111, 121, 109, 101, 110, + 116, 115, 165, 110, 111, 100, 101, 115, 128, 170, 82, 101, 112, 108, + 105, 99, 97, 83, 101, 116, 132, 165, 115, 104, 97, 112, 101, 168, 104, + 101, 112, 116, 97, 103, 111, 110, 165, 108, 97, 98, 101, 108, 171, + 114, 101, 112, 108, 105, 99, 97, 32, 115, 101, 116, 172, 108, 97, 98, + 101, 108, 95, 112, 108, 117, 114, 97, 108, 172, 114, 101, 112, 108, + 105, 99, 97, 32, 115, 101, 116, 115, 165, 110, 111, 100, 101, 115, + 128, 174, 67, 111, 110, 116, 97, 105, 110, 101, 114, 73, 109, 97, 103, + 101, 132, 165, 115, 104, 97, 112, 101, 167, 104, 101, 120, 97, 103, + 111, 110, 165, 108, 97, 98, 101, 108, 165, 105, 109, 97, 103, 101, + 172, 108, 97, 98, 101, 108, 95, 112, 108, 117, 114, 97, 108, 166, 105, + 109, 97, 103, 101, 115, 165, 110, 111, 100, 101, 115, 128, 164, 72, + 111, 115, 116, 132, 165, 115, 104, 97, 112, 101, 166, 99, 105, 114, + 99, 108, 101, 165, 108, 97, 98, 101, 108, 164, 104, 111, 115, 116, + 172, 108, 97, 98, 101, 108, 95, 112, 108, 117, 114, 97, 108, 165, 104, + 111, 115, 116, 115, 165, 110, 111, 100, 101, 115, 128, 167, 69, 67, + 83, 84, 97, 115, 107, 132, 165, 115, 104, 97, 112, 101, 168, 104, 101, + 112, 116, 97, 103, 111, 110, 165, 108, 97, 98, 101, 108, 164, 116, 97, + 115, 107, 172, 108, 97, 98, 101, 108, 95, 112, 108, 117, 114, 97, 108, + 165, 116, 97, 115, 107, 115, 165, 110, 111, 100, 101, 115, 128, 170, + 69, 67, 83, 83, 101, 114, 118, 105, 99, 101, 132, 165, 115, 104, 97, + 112, 101, 168, 104, 101, 112, 116, 97, 103, 111, 110, 165, 108, 97, + 98, 101, 108, 167, 115, 101, 114, 118, 105, 99, 101, 172, 108, 97, 98, + 101, 108, 95, 112, 108, 117, 114, 97, 108, 168, 115, 101, 114, 118, + 105, 99, 101, 115, 165, 110, 111, 100, 101, 115, 128, 172, 83, 119, + 97, 114, 109, 83, 101, 114, 118, 105, 99, 101, 132, 165, 115, 104, 97, + 112, 101, 168, 104, 101, 112, 116, 97, 103, 111, 110, 165, 108, 97, + 98, 101, 108, 167, 115, 101, 114, 118, 105, 99, 101, 172, 108, 97, 98, + 101, 108, 95, 112, 108, 117, 114, 97, 108, 168, 115, 101, 114, 118, + 105, 99, 101, 115, 165, 110, 111, 100, 101, 115, 128, 167, 79, 118, + 101, 114, 108, 97, 121, 133, 165, 115, 104, 97, 112, 101, 166, 99, + 105, 114, 99, 108, 101, 165, 108, 97, 98, 101, 108, 164, 112, 101, + 101, 114, 172, 108, 97, 98, 101, 108, 95, 112, 108, 117, 114, 97, 108, + 165, 112, 101, 101, 114, 115, 165, 110, 111, 100, 101, 115, 129, 188, + 35, 100, 111, 99, 107, 101, 114, 95, 112, 101, 101, 114, 95, 105, 112, + 45, 49, 55, 50, 45, 50, 48, 45, 49, 45, 49, 54, 56, 139, 162, 105, + 100, 188, 35, 100, 111, 99, 107, 101, 114, 95, 112, 101, 101, 114, 95, + 105, 112, 45, 49, 55, 50, 45, 50, 48, 45, 49, 45, 49, 54, 56, 168, + 116, 111, 112, 111, 108, 111, 103, 121, 167, 111, 118, 101, 114, 108, + 97, 121, 168, 99, 111, 117, 110, 116, 101, 114, 115, 128, 164, 115, + 101, 116, 115, 129, 174, 108, 111, 99, 97, 108, 95, 110, 101, 116, + 119, 111, 114, 107, 115, 145, 173, 49, 55, 50, 46, 49, 56, 46, 48, 46, + 48, 47, 49, 54, 169, 97, 100, 106, 97, 99, 101, 110, 99, 121, 192, + 165, 101, 100, 103, 101, 115, 128, 168, 99, 111, 110, 116, 114, 111, + 108, 115, 128, 174, 108, 97, 116, 101, 115, 116, 67, 111, 110, 116, + 114, 111, 108, 115, 128, 166, 108, 97, 116, 101, 115, 116, 128, 167, + 112, 97, 114, 101, 110, 116, 115, 128, 168, 99, 104, 105, 108, 100, + 114, 101, 110, 192, 178, 109, 101, 116, 97, 100, 97, 116, 97, 95, 116, + 101, 109, 112, 108, 97, 116, 101, 115, 129, 176, 119, 101, 97, 118, + 101, 95, 101, 110, 99, 114, 121, 112, 116, 105, 111, 110, 132, 162, + 105, 100, 176, 119, 101, 97, 118, 101, 95, 101, 110, 99, 114, 121, + 112, 116, 105, 111, 110, 165, 108, 97, 98, 101, 108, 170, 69, 110, 99, + 114, 121, 112, 116, 105, 111, 110, 168, 112, 114, 105, 111, 114, 105, + 116, 121, 203, 64, 16, 0, 0, 0, 0, 0, 0, 164, 102, 114, 111, 109, 166, + 108, 97, 116, 101, 115, 116, 168, 83, 97, 109, 112, 108, 105, 110, + 103, 130, 165, 67, 111, 117, 110, 116, 0, 165, 84, 111, 116, 97, 108, + 0, 166, 87, 105, 110, 100, 111, 119, 0, 168, 83, 104, 111, 114, 116, + 99, 117, 116, 194, 167, 80, 108, 117, 103, 105, 110, 115, 144, 162, + 73, 68, 179, 51, 56, 57, 52, 48, 54, 57, 54, 53, 56, 51, 52, 50, 50, + 53, 51, 52, 49, 57}