@@ -26,21 +26,16 @@ import (
2626 "encoding/json"
2727 "errors"
2828 "fmt"
29- "os"
3029 "reflect"
31- "sync/atomic"
3230 "testing"
3331 "time"
3432
3533 "github.com/skydive-project/skydive/api/types"
3634 "github.com/skydive-project/skydive/common"
37- "github.com/skydive-project/skydive/config"
3835 "github.com/skydive-project/skydive/graffiti/graph"
3936 g "github.com/skydive-project/skydive/gremlin"
40- shttp "github.com/skydive-project/skydive/http"
4137 "github.com/skydive-project/skydive/topology"
4238 "github.com/skydive-project/skydive/topology/probes/netlink"
43- ws "github.com/skydive-project/skydive/websocket"
4439)
4540
4641func TestBridgeOVS (t * testing.T ) {
@@ -612,116 +607,6 @@ func TestOVSOwnershipLink(t *testing.T) {
612607 RunTest (t , test )
613608}
614609
615- type TopologyInjecter struct {
616- ws.DefaultSpeakerEventHandler
617- connected int32
618- }
619-
620- func (t * TopologyInjecter ) OnConnected (c ws.Speaker ) {
621- atomic .StoreInt32 (& t .connected , 1 )
622- }
623-
624- func TestQueryMetadata (t * testing.T ) {
625- test := & Test {
626- setupFunction : func (c * TestContext ) error {
627- authOptions := & shttp.AuthenticationOpts {}
628- addresses , err := config .GetAnalyzerServiceAddresses ()
629- if err != nil || len (addresses ) == 0 {
630- return fmt .Errorf ("Unable to get the analyzers list: %s" , err .Error ())
631- }
632-
633- hostname , _ := os .Hostname ()
634- wspool := ws .NewStructClientPool ("TestQueryMetadata" )
635- for _ , sa := range addresses {
636- opts := ws.ClientOpts {
637- AuthOpts : authOptions ,
638- QueueSize : 1000 ,
639- WriteCompression : true ,
640- }
641-
642- client := ws .NewClient (hostname + "-cli" , common .UnknownService , config .GetURL ("ws" , sa .Addr , sa .Port , "/ws/publisher" ), opts )
643- wspool .AddClient (client )
644- }
645-
646- masterElection := ws .NewMasterElection (wspool )
647-
648- eventHandler := & TopologyInjecter {}
649- wspool .AddEventHandler (eventHandler )
650- wspool .ConnectAll ()
651-
652- err = common .Retry (func () error {
653- if atomic .LoadInt32 (& eventHandler .connected ) != 1 {
654- return errors .New ("Not connected through WebSocket" )
655- }
656- return nil
657- }, 10 , time .Second )
658-
659- if err != nil {
660- return err
661- }
662-
663- m := graph.Metadata {
664- "A" : map [string ]interface {}{
665- "B" : map [string ]interface {}{
666- "C" : 123 ,
667- "D" : []interface {}{1 , 2 , 3 },
668- "E" : []interface {}{"a" , "b" , "c" },
669- },
670- "F" : map [string ]interface {}{
671- "G" : 123 ,
672- "H" : []interface {}{true , true },
673- },
674- },
675- }
676- n := graph .CreateNode (graph .Identifier ("123" ), m , graph .TimeUTC (), "test" , common .AgentService )
677-
678- // The first message should be rejected as it has no 'Type' attribute
679- msg := ws .NewStructMessage (graph .Namespace , graph .NodeAddedMsgType , n )
680- masterElection .SendMessageToMaster (msg )
681-
682- m .SetField ("Type" , "external" )
683- m .SetField ("Name" , "testNode" )
684-
685- msg = ws .NewStructMessage (graph .Namespace , graph .NodeAddedMsgType , n )
686- masterElection .SendMessageToMaster (msg )
687-
688- return nil
689- },
690-
691- mode : Replay ,
692-
693- checks : []CheckFunction {func (c * CheckContext ) error {
694- gh := c .gh
695- prefix := c .gremlin
696-
697- _ , err := gh .GetNode (prefix .V ().Has ("A.F.G" , 123 ))
698- if err != nil {
699- return err
700- }
701-
702- _ , err = gh .GetNode (prefix .V ().Has ("A.B.C" , 123 ))
703- if err != nil {
704- return err
705- }
706-
707- _ , err = gh .GetNode (prefix .V ().Has ("A.B.D" , 1 ))
708- if err != nil {
709- return err
710- }
711-
712- _ , err = gh .GetNode (prefix .V ().Has ("A.B.E" , "b" ))
713- if err != nil {
714- return err
715- }
716-
717- _ , err = gh .GetNode (prefix .V ().Has ("A.F.H" , true ))
718- return err
719- }},
720- }
721-
722- RunTest (t , test )
723- }
724-
725610func TestNodeRuleCreate (t * testing.T ) {
726611 nodeRule := & types.NodeRule {
727612 Action : "create" ,
@@ -884,10 +769,19 @@ func TestAgentMetadata(t *testing.T) {
884769 checks : []CheckFunction {
885770 func (c * CheckContext ) error {
886771 if _ , err := c .gh .GetNode (c .gremlin .V ().Has ("mydict.value" , 123 )); err != nil {
887- return fmt . Errorf ( "Failed to find the host node with mydict.value metadata" )
772+ return err
888773 }
889774
890- return nil
775+ if _ , err := c .gh .GetNode (c .gremlin .V ().Has ("myarrays.integers" , 1 )); err != nil {
776+ return err
777+ }
778+
779+ if _ , err := c .gh .GetNode (c .gremlin .V ().Has ("myarrays.strings" , "cat" )); err != nil {
780+ return err
781+ }
782+
783+ _ , err := c .gh .GetNode (c .gremlin .V ().Has ("myarrays.bools" , true ))
784+ return err
891785 },
892786 },
893787 }
0 commit comments