summaryrefslogtreecommitdiff
path: root/config/lives_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/lives_test.go')
-rw-r--r--config/lives_test.go92
1 files changed, 14 insertions, 78 deletions
diff --git a/config/lives_test.go b/config/lives_test.go
index d6097b5..06da8f0 100644
--- a/config/lives_test.go
+++ b/config/lives_test.go
@@ -9,7 +9,7 @@ import (
"phabricator.wikimedia.org/source/blubber/config"
)
-func TestLivesConfig(t *testing.T) {
+func TestLivesConfigYAML(t *testing.T) {
cfg, err := config.ReadConfig([]byte(`---
version: v1
base: foo
@@ -95,27 +95,23 @@ func TestLivesConfigInstructions(t *testing.T) {
func TestLivesConfigValidation(t *testing.T) {
t.Run("in", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- in: /foo`))
+ err := config.Validate(config.LivesConfig{
+ In: "/foo",
+ })
assert.False(t, config.IsValidationError(err))
})
t.Run("optional", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives: {}`))
+ err := config.Validate(config.LivesConfig{})
assert.False(t, config.IsValidationError(err))
})
t.Run("non-root", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- in: /`))
+ err := config.Validate(config.LivesConfig{
+ In: "/",
+ })
if assert.True(t, config.IsValidationError(err)) {
msg := config.HumanizeValidationError(err)
@@ -125,10 +121,9 @@ func TestLivesConfigValidation(t *testing.T) {
})
t.Run("non-root tricky", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- in: /foo/..`))
+ err := config.Validate(config.LivesConfig{
+ In: "/foo/..",
+ })
if assert.True(t, config.IsValidationError(err)) {
msg := config.HumanizeValidationError(err)
@@ -138,10 +133,9 @@ func TestLivesConfigValidation(t *testing.T) {
})
t.Run("absolute", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- in: foo/bar`))
+ err := config.Validate(config.LivesConfig{
+ In: "foo/bar",
+ })
if assert.True(t, config.IsValidationError(err)) {
msg := config.HumanizeValidationError(err)
@@ -150,62 +144,4 @@ func TestLivesConfigValidation(t *testing.T) {
}
})
})
-
- t.Run("as", func(t *testing.T) {
- t.Run("ok", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- as: foo-bar.baz`))
-
- assert.False(t, config.IsValidationError(err))
- })
-
- t.Run("optional", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives: {}`))
-
- assert.False(t, config.IsValidationError(err))
- })
-
- t.Run("no spaces", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- as: foo bar`))
-
- if assert.True(t, config.IsValidationError(err)) {
- msg := config.HumanizeValidationError(err)
-
- assert.Equal(t, `as: "foo bar" is not a valid user name`, msg)
- }
- })
-
- t.Run("long enough", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- as: fo`))
-
- if assert.True(t, config.IsValidationError(err)) {
- msg := config.HumanizeValidationError(err)
-
- assert.Equal(t, `as: "fo" is not a valid user name`, msg)
- }
- })
-
- t.Run("not root", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
- version: v1
- lives:
- as: root`))
-
- if assert.True(t, config.IsValidationError(err)) {
- msg := config.HumanizeValidationError(err)
-
- assert.Equal(t, `as: "root" is not a valid user name`, msg)
- }
- })
- })
}