Example #1
0
func TestFlowTable_jsonFlowConversationEthernetPath(t *testing.T) {
	ft := flow.NewTestFlowTableComplex(t, nil, nil)
	fa := &FlowApi{
		FlowTable: ft,
	}

	statStr := fa.jsonFlowConversationEthernetPath(flow.FlowProtocol_ETHERNET)
	if statStr == `{"nodes":[],"links":[]}` {
		t.Error("stat should not be empty")
	}

	var decoded interface{}
	if err := json.Unmarshal([]byte(statStr), &decoded); err != nil {
		t.Error("JSON parsing failed:", err)
	}

	schema := v.Object(
		v.ObjKV("nodes", v.Array(v.ArrEach(v.Object(
			v.ObjKV("name", v.String(v.StrMin(1))),
			v.ObjKV("group", v.Number(v.NumMin(0), v.NumMax(20))),
		)))),
		v.ObjKV("links", v.Array(v.ArrEach(v.Object(
			v.ObjKV("source", v.Number(v.NumMin(0), v.NumMax(20))),
			v.ObjKV("target", v.Number(v.NumMin(0), v.NumMax(20))),
			v.ObjKV("value", v.Number(v.NumMin(0), v.NumMax(9999))),
		)))),
	)

	if path, err := schema.Validate(decoded); err != nil {
		t.Errorf("Failed (%s). Path: %s", err, path)
	}
}
Example #2
0
func test_jsonFlowDiscovery(t *testing.T, DiscoType discoType) {
	ft := flow.NewTestFlowTableComplex(t, nil, nil)
	fa := &FlowApi{
		FlowTable: ft,
	}
	disco := fa.jsonFlowDiscovery(DiscoType)

	if disco == `{"name":"root","children":[]}` {
		t.Error("disco should not be empty")
	}

	var decoded interface{}
	if err := json.Unmarshal([]byte(disco), &decoded); err != nil {
		t.Error("JSON parsing failed:", err)
	}

	schema := v.Object(
		v.ObjKV("name", v.String(v.StrMin(1))), // root
		v.ObjKV("children", v.Array(v.ArrEach(v.Object(
			v.ObjKV("name", v.String(v.StrMin(1))), // Ethernet
			v.ObjKV("children", v.Array(v.ArrEach(v.Object(
				v.ObjKV("name", v.String(v.StrMin(1))), // IPv4
				v.ObjKV("children", v.Array(v.ArrEach(v.Object(
					v.ObjKV("name", v.String(v.StrMin(1))), // TCP or UDP
					v.ObjKV("children", v.Array(v.ArrEach(v.Object(
						v.ObjKV("name", v.String(v.StrMin(1))), // Payload
						v.ObjKV("size", v.Number(v.NumMin(0), v.NumMax(9999))),
					)))),
				)))),
			)))),
		)))),
	)

	if path, err := schema.Validate(decoded); err != nil {
		t.Errorf("Failed (%s). Path: %s", err, path)
	}
}