Skip to content
Snippets Groups Projects
integration_test.go 3.11 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    
    import (
    	"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
    	"context"
    	gpb "github.com/openconfig/gnmi/proto/gnmi"
    	"testing"
    	"time"
    )
    
    var address = "141.100.70.171:6030"
    
    
    func TestGnmi_SetIntegration(t *testing.T) {
    	if testing.Short() {
    		t.Skip("skipping integration test")
    	}
    
    	t.Run("Test GNMI Set", func(t *testing.T){
    		cfg := &gnmi.Config{
    			Addr:     address,
    			Username: "admin",
    			Password: "arista",
    			Encoding: gpb.Encoding_JSON_IETF,
    		}
    		transport,err := NewGnmiTransport(cfg)
    		if err != nil {
    			t.Error(err)
    		}
    		p := []string{"/interfaces/interface"}
    		resp, err := transport.Set(context.Background(), p...)
    		if err != nil {
    			t.Error(err)
    		}
    		if resp == nil {
    			t.Error("resp is nil")
    		}
    	})
    
    }
    
    func TestGnmi_GetIntegration(t *testing.T) {
    	if testing.Short() {
    		t.Skip("skipping integration test")
    	}
    
    	t.Run("Test GNMI Get", func(t *testing.T){
    		cfg := &gnmi.Config{
    			Addr:     address,
    			Username: "admin",
    			Password: "arista",
    			Encoding: gpb.Encoding_JSON_IETF,
    		}
    		transport,err := NewGnmiTransport(cfg)
    		if err != nil {
    			t.Error(err)
    		}
    		p := []string{"/interfaces/interface"}
    		resp, err := transport.Get(context.Background(), p...)
    		if err != nil {
    			t.Error(err)
    		}
    		if resp == nil {
    			t.Error("resp is nil")
    		}
    	})
    
    }
    
    func TestGnmi_SubscribeIntegration(t *testing.T) {
    	if testing.Short() {
    		t.Skip("skipping integration test")
    	}
    
    	t.Run("Test GNMI Subscribe", func(t *testing.T){
    		cfg := &gnmi.Config{
    			Addr:     address,
    			Username: "admin",
    			Password: "arista",
    			Encoding: gpb.Encoding_JSON_IETF,
    		}
    		transport,_ := NewGnmiTransport(cfg)
    
    		paths := []string{"/interfaces/interface/name"}
    
    		opts := &gnmi.SubscribeOptions{
    			UpdatesOnly:       false,
    			Prefix:            "",
    			Mode:              "stream",
    			StreamMode:        "sample",
    			SampleInterval:    uint64(10 * time.Second.Nanoseconds()),
    			SuppressRedundant: false,
    			HeartbeatInterval: uint64(time.Second.Nanoseconds()),
    			Paths:             gnmi.SplitPaths(paths),
    			Origin:            "",
    			Target:            address,
    		}
    		ctx := context.WithValue(context.Background(), "opts", opts)
    		d := time.Now().Add(60 * time.Second)
    		ctx, cancel := context.WithDeadline(ctx, d)
    		defer cancel()
    		go func() {
    			if err := transport.Subscribe(ctx); err != nil {
    				t.Error(err)
    			}
    		}()
    		time.Sleep(time.Second * 50)
    	})
    
    }
    
    func TestGnmi_CapabilitiesIntegration(t *testing.T) {
    	if testing.Short() {
    		t.Skip("skipping integration test")
    	}
    
    	t.Run("Test GNMI Capabilities", func(t *testing.T){
    	cfg := &gnmi.Config{
    		Addr:     address,
    		Username: "admin",
    		Password: "arista",
    		Encoding: gpb.Encoding_JSON_IETF,
    	}
    	transport,err := NewGnmiTransport(cfg)
    	if err != nil {
    		t.Error(err)
    	}
    	resp, err := transport.Capabilities(context.Background())
    	if err != nil {
    		t.Error(err)
    	}
    	if resp == nil {
    		t.Error("resp is nil")
    	}
    	})
    
    }
    
    func TestPndImplementation_RequestAllIntegration(t *testing.T) {
    	if testing.Short() {
    		t.Skip("skipping integration test")
    	}
    
    }
    
    func TestPndImplementation_RequestIntegration(t *testing.T) {
    	if testing.Short() {
    		t.Skip("skipping integration test")
    	}