From 43bc032fc39804d56864a9013a92ea37e3903219 Mon Sep 17 00:00:00 2001
From: Oliver Herms <oliver.herms@exaring.de>
Date: Wed, 18 Apr 2018 17:23:51 +0200
Subject: [PATCH] Fixing path selection

---
 rt/route.go      |  2 +-
 rt/route_test.go | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/rt/route.go b/rt/route.go
index 42dd4162..f9027486 100644
--- a/rt/route.go
+++ b/rt/route.go
@@ -116,7 +116,7 @@ func getBestProtocol(paths []*Path) uint8 {
 			continue
 		}
 
-		if p.Type > best {
+		if p.Type < best {
 			best = p.Type
 		}
 	}
diff --git a/rt/route_test.go b/rt/route_test.go
index d4633694..ecd88a04 100644
--- a/rt/route_test.go
+++ b/rt/route_test.go
@@ -367,3 +367,29 @@ func TestAddPaths(t *testing.T) {
 		assert.Equal(t, test.expected, test.route)
 	}
 }
+
+func TestGetBestProtocol(t *testing.T) {
+	tests := []struct {
+		name     string
+		input    []*Path
+		expected uint8
+	}{
+		{
+			name: "Foo",
+			input: []*Path{
+				{
+					Type: BGPPathType,
+				},
+				{
+					Type: StaticPathType,
+				},
+			},
+			expected: StaticPathType,
+		},
+	}
+
+	for _, test := range tests {
+		res := getBestProtocol(test.input)
+		assert.Equal(t, test.expected, res)
+	}
+}
-- 
GitLab