aboutsummaryrefslogtreecommitdiff
path: root/pkg/config
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/config')
-rw-r--r--pkg/config/config.go7
-rw-r--r--pkg/config/config_test.go22
-rw-r--r--pkg/config/error.go15
-rw-r--r--pkg/config/error_test.go2
-rw-r--r--pkg/config/test_data/complete.yaml1
-rw-r--r--pkg/config/test_data/invalid_trainStop.yaml4
-rw-r--r--pkg/config/test_data/minimal.yaml1
-rw-r--r--pkg/config/test_data/minimal_with_hostname.yaml1
8 files changed, 9 insertions, 44 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 795ccd0..442695c 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -9,7 +9,6 @@ import (
)
var validToken = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
-var validTrainStop = regexp.MustCompile(`^[a-zA-Z0-9:_]+$`)
type Config struct {
// Address is the hostname or ip the web server will listen to
@@ -18,8 +17,6 @@ type Config struct {
Port string `yaml:"port"`
// Token is the sncf api token
Token string `yaml:"token"`
- // TrainStop is the navitia code of the train stop the webapp will monitor
- TrainStop string `yaml:"trainStop"`
}
func (c *Config) validate() error {
@@ -43,10 +40,6 @@ func (c *Config) validate() error {
if ok := validToken.MatchString(c.Token); !ok {
return newInvalidTokenError(c.Token)
}
- // TrainStop
- if ok := validTrainStop.MatchString(c.TrainStop); !ok {
- return newInvalidTrainStopError(c.TrainStop)
- }
return nil
}
diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go
index 02f2840..43d4a48 100644
--- a/pkg/config/config_test.go
+++ b/pkg/config/config_test.go
@@ -11,26 +11,23 @@ import (
func TestLoadFile(t *testing.T) {
// Minimal yaml file
minimalConfig := Config{
- Address: "127.0.0.1",
- Port: "8080",
- Token: "12345678-9abc-def0-1234-56789abcdef0",
- TrainStop: "ABCD:test:01",
+ Address: "127.0.0.1",
+ Port: "8080",
+ Token: "12345678-9abc-def0-1234-56789abcdef0",
}
// Minimal yaml file with hostname resolving
minimalConfigWithResolving := Config{
- Address: "localhost",
- Port: "www",
- Token: "12345678-9abc-def0-1234-56789abcdef0",
- TrainStop: "VWXY_Z:test:90",
+ Address: "localhost",
+ Port: "www",
+ Token: "12345678-9abc-def0-1234-56789abcdef0",
}
// Complete yaml file
completeConfig := Config{
- Address: "127.0.0.2",
- Port: "8082",
- Token: "12345678-9abc-def0-1234-56789abcdef0",
- TrainStop: "ABCD:test:01",
+ Address: "127.0.0.2",
+ Port: "8082",
+ Token: "12345678-9abc-def0-1234-56789abcdef0",
}
// Test cases
@@ -46,7 +43,6 @@ func TestLoadFile(t *testing.T) {
{"Unresolvable address should fail to load", "test_data/invalid_address_unresolvable.yaml", nil, &InvalidAddressError{}},
{"Invalid port should fail to load", "test_data/invalid_port.yaml", nil, &InvalidPortError{}},
{"Invalid token should fail to load", "test_data/invalid_token.yaml", nil, &InvalidTokenError{}},
- {"Invalid trainStop should fail to load", "test_data/invalid_trainStop.yaml", nil, &InvalidTrainStopError{}},
{"Minimal config", "test_data/minimal.yaml", &minimalConfig, nil},
{"Minimal config with resolving", "test_data/minimal_with_hostname.yaml", &minimalConfigWithResolving, nil},
{"Complete config", "test_data/complete.yaml", &completeConfig, nil},
diff --git a/pkg/config/error.go b/pkg/config/error.go
index 41a323c..c49b6a9 100644
--- a/pkg/config/error.go
+++ b/pkg/config/error.go
@@ -90,18 +90,3 @@ func newInvalidTokenError(token string) error {
token: token,
}
}
-
-// Invalid trainStop field error
-type InvalidTrainStopError struct {
- trainStop string
-}
-
-func (e *InvalidTrainStopError) Error() string {
- return fmt.Sprintf("Invalid trainStop %s : it must be a string that lookslike \"stop_area:SNCF:87723502\" (make sure to quote the string because of the colon characters)", e.trainStop)
-}
-
-func newInvalidTrainStopError(trainStop string) error {
- return &InvalidTrainStopError{
- trainStop: trainStop,
- }
-}
diff --git a/pkg/config/error_test.go b/pkg/config/error_test.go
index 4a80b05..f9807c1 100644
--- a/pkg/config/error_test.go
+++ b/pkg/config/error_test.go
@@ -17,6 +17,4 @@ func TestErrorsCoverage(t *testing.T) {
_ = invalidPortErr.Unwrap()
invalidTokenErr := InvalidTokenError{}
_ = invalidTokenErr.Error()
- invalidTrainStopErr := InvalidTrainStopError{}
- _ = invalidTrainStopErr.Error()
}
diff --git a/pkg/config/test_data/complete.yaml b/pkg/config/test_data/complete.yaml
index e34db15..2944645 100644
--- a/pkg/config/test_data/complete.yaml
+++ b/pkg/config/test_data/complete.yaml
@@ -1,4 +1,3 @@
address: 127.0.0.2
port: 8082
token: 12345678-9abc-def0-1234-56789abcdef0
-trainStop: "ABCD:test:01"
diff --git a/pkg/config/test_data/invalid_trainStop.yaml b/pkg/config/test_data/invalid_trainStop.yaml
deleted file mode 100644
index 159950d..0000000
--- a/pkg/config/test_data/invalid_trainStop.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-address: 127.0.0.2
-port: 8082
-token: 12345678-9abc-def0-1234-56789abcdef0
-trainStop: =
diff --git a/pkg/config/test_data/minimal.yaml b/pkg/config/test_data/minimal.yaml
index 5092997..932fca3 100644
--- a/pkg/config/test_data/minimal.yaml
+++ b/pkg/config/test_data/minimal.yaml
@@ -1,2 +1 @@
token: 12345678-9abc-def0-1234-56789abcdef0
-trainStop: "ABCD:test:01"
diff --git a/pkg/config/test_data/minimal_with_hostname.yaml b/pkg/config/test_data/minimal_with_hostname.yaml
index 116688a..dbede14 100644
--- a/pkg/config/test_data/minimal_with_hostname.yaml
+++ b/pkg/config/test_data/minimal_with_hostname.yaml
@@ -1,4 +1,3 @@
address: localhost
port: www
token: 12345678-9abc-def0-1234-56789abcdef0
-trainStop: "VWXY_Z:test:90"