Repository: scionproto/scion
Pull request #3814 (2020-07-01 14:50:14)

sig: improve config tests
Refactor config tests to be importable from other locations.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/scionproto/scion/3814)
<!-- Reviewable:end -->



Patch:
diff --git a/go/pkg/sig/config/BUILD.bazel b/go/pkg/sig/config/BUILD.bazel
index 20142eb10..c0da1581e 100644
--- a/go/pkg/sig/config/BUILD.bazel
+++ b/go/pkg/sig/config/BUILD.bazel
@@ -24,7 +24,7 @@ go_test(
     deps = [
         "//go/lib/env/envtest:go_default_library",
         "//go/lib/log/logtest:go_default_library",
-        "//go/lib/xtest:go_default_library",
+        "//go/pkg/sig/config/configtest:go_default_library",
         "@com_github_pelletier_go_toml//:go_default_library",
         "@com_github_stretchr_testify//assert:go_default_library",
     ],


Test patch:
diff --git a/go/pkg/sig/config/config_test.go b/go/pkg/sig/config/config_test.go
index 2f71014ac..e2ef33784 100644
--- a/go/pkg/sig/config/config_test.go
+++ b/go/pkg/sig/config/config_test.go
@@ -12,11 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package config
+package config_test
 
 import (
 	"bytes"
-	"net"
 	"testing"
 
 	toml "github.com/pelletier/go-toml"
@@ -24,43 +23,28 @@ import (
 
 	"github.com/scionproto/scion/go/lib/env/envtest"
 	"github.com/scionproto/scion/go/lib/log/logtest"
-	"github.com/scionproto/scion/go/lib/xtest"
+	"github.com/scionproto/scion/go/pkg/sig/config"
+	"github.com/scionproto/scion/go/pkg/sig/config/configtest"
 )
 
 func TestConfigSample(t *testing.T) {
 	var sample bytes.Buffer
-	var cfg Config
+	var cfg config.Config
 	cfg.Sample(&sample, nil, nil)
 
 	InitTestConfig(&cfg)
 	err := toml.NewDecoder(bytes.NewReader(sample.Bytes())).Strict(true).Decode(&cfg)
 	assert.NoError(t, err)
-	CheckTestConfig(t, &cfg, idSample)
+	CheckTestConfig(t, &cfg, "sig4")
 }
 
-func InitTestConfig(cfg *Config) {
+func InitTestConfig(cfg *config.Config) {
 	envtest.InitTest(nil, &cfg.Metrics, nil, &cfg.Sciond)
 	logtest.InitTestLogging(&cfg.Logging)
-	InitTestSigConf(&cfg.Sig)
 }
 
-func InitTestSigConf(cfg *SigConf) {
-
-}
-
-func CheckTestConfig(t *testing.T, cfg *Config, id string) {
+func CheckTestConfig(t *testing.T, cfg *config.Config, id string) {
 	envtest.CheckTest(t, nil, &cfg.Metrics, nil, &cfg.Sciond, id)
 	logtest.CheckTestLogging(t, &cfg.Logging, id)
-	CheckTestSigConf(t, &cfg.Sig, id)
-}
-
-func CheckTestSigConf(t *testing.T, cfg *SigConf, id string) {
-	assert.Equal(t, "sig4", cfg.ID)
-	assert.Equal(t, "/etc/scion/sig/sig.json", cfg.SIGConfig)
-	assert.Equal(t, xtest.MustParseIA("1-ff00:0:113"), cfg.IA)
-	assert.Equal(t, net.ParseIP("192.0.2.100"), cfg.IP)
-	assert.Equal(t, DefaultCtrlPort, int(cfg.CtrlPort))
-	assert.Equal(t, DefaultEncapPort, int(cfg.EncapPort))
-	assert.Equal(t, DefaultTunName, cfg.Tun)
-	assert.Equal(t, DefaultTunRTableId, cfg.TunRTableId)
+	configtest.CheckTestSIG(t, &cfg.Sig, id)
 }
diff --git a/go/pkg/sig/config/configtest/BUILD.bazel b/go/pkg/sig/config/configtest/BUILD.bazel
new file mode 100644
index 000000000..7d4c5f6e6
--- /dev/null
+++ b/go/pkg/sig/config/configtest/BUILD.bazel
@@ -0,0 +1,13 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+go_library(
+    name = "go_default_library",
+    srcs = ["configtest.go"],
+    importpath = "github.com/scionproto/scion/go/pkg/sig/config/configtest",
+    visibility = ["//visibility:public"],
+    deps = [
+        "//go/lib/xtest:go_default_library",
+        "//go/pkg/sig/config:go_default_library",
+        "@com_github_stretchr_testify//assert:go_default_library",
+    ],
+)
diff --git a/go/pkg/sig/config/configtest/configtest.go b/go/pkg/sig/config/configtest/configtest.go
new file mode 100644
index 000000000..672c883b2
--- /dev/null
+++ b/go/pkg/sig/config/configtest/configtest.go
@@ -0,0 +1,36 @@
+// Copyright 2020 Anapaya Systems
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package configtest
+
+import (
+	"net"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+
+	"github.com/scionproto/scion/go/lib/xtest"
+	"github.com/scionproto/scion/go/pkg/sig/config"
+)
+
+func CheckTestSIG(t *testing.T, cfg *config.SigConf, id string) {
+	assert.Equal(t, id, cfg.ID)
+	assert.Equal(t, "/etc/scion/sig/sig.json", cfg.SIGConfig)
+	assert.Equal(t, xtest.MustParseIA("1-ff00:0:113"), cfg.IA)
+	assert.Equal(t, net.ParseIP("192.0.2.100"), cfg.IP)
+	assert.Equal(t, config.DefaultCtrlPort, int(cfg.CtrlPort))
+	assert.Equal(t, config.DefaultEncapPort, int(cfg.EncapPort))
+	assert.Equal(t, config.DefaultTunName, cfg.Tun)
+	assert.Equal(t, config.DefaultTunRTableId, cfg.TunRTableId)
+}