Browse Source

:gear: Add 2-node connection test

Ettore Di Giacinto 3 years ago
parent
commit
82c3e0ae52
4 changed files with 86 additions and 2 deletions
  1. 4 2
      .github/tests.sh
  2. 2 0
      pkg/edgevpn/edgevpn.go
  3. 28 0
      pkg/edgevpn/edgevpn_suite_test.go
  4. 52 0
      pkg/edgevpn/edgevpn_test.go

+ 4 - 2
.github/tests.sh

@@ -2,9 +2,11 @@
 
 set -ex
 
-./edgevpn api &
-
 GO111MODULE=off go get github.com/onsi/ginkgo/ginkgo
 GO111MODULE=off go get github.com/onsi/gomega/...
 
+go test ./pkg/...
+
+./edgevpn api &
+
 TEST_INSTANCE="http://localhost:8080" go test ./api/client

+ 2 - 0
pkg/edgevpn/edgevpn.go

@@ -36,6 +36,7 @@ import (
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/edgevpn/types"
 	hub "github.com/mudler/edgevpn/pkg/hub"
+	"github.com/mudler/edgevpn/pkg/logger"
 	"github.com/pkg/errors"
 	"github.com/songgao/packets/ethernet"
 	"github.com/songgao/water"
@@ -71,6 +72,7 @@ func New(p ...Option) *EdgeVPN {
 		SealKeyLength:            12,
 		Options:                  defaultLibp2pOptions,
 		Timeout:                  15 * time.Second,
+		Logger:                   logger.New(log.LevelDebug),
 	}
 	c.Apply(p...)
 

+ 28 - 0
pkg/edgevpn/edgevpn_suite_test.go

@@ -0,0 +1,28 @@
+// Copyright © 2022 Ettore Di Giacinto <[email protected]>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, see <http://www.gnu.org/licenses/>.
+
+package edgevpn_test
+
+import (
+	"testing"
+
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+)
+
+func TestEdgeVPN(t *testing.T) {
+	RegisterFailHandler(Fail)
+	RunSpecs(t, "EdgeVPN Suite")
+}

+ 52 - 0
pkg/edgevpn/edgevpn_test.go

@@ -0,0 +1,52 @@
+// Copyright © 2022 Ettore Di Giacinto <[email protected]>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, see <http://www.gnu.org/licenses/>.
+
+package edgevpn_test
+
+import (
+	"context"
+	"time"
+
+	"github.com/ipfs/go-log"
+	"github.com/libp2p/go-libp2p-core/peer"
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+
+	"github.com/mudler/edgevpn/pkg/blockchain"
+	. "github.com/mudler/edgevpn/pkg/edgevpn"
+	"github.com/mudler/edgevpn/pkg/logger"
+)
+
+var _ = Describe("EdgeVPN", func() {
+	token := GenerateNewConnectionData().Base64()
+
+	l := Logger(logger.New(log.LevelFatal))
+
+	e := New(FromBase64(true, true, token), WithStore(&blockchain.MemoryStore{}), l)
+	e2 := New(FromBase64(true, true, token), WithStore(&blockchain.MemoryStore{}), l)
+
+	Context("Connection", func() {
+		It("see each other node ID", func() {
+			ctx, cancel := context.WithCancel(context.Background())
+			defer cancel()
+			e.Join(ctx)
+			e2.Join(ctx)
+
+			Eventually(func() []peer.ID {
+				return e.Host().Network().Peers()
+			}, 100*time.Second, 1*time.Second).Should(ContainElement(e2.Host().ID()))
+		})
+	})
+})