summaryrefslogtreecommitdiff
path: root/config/user_test.go
blob: f908f886176801bebd0e6cb8c252ba5ca35d192e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package config_test

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"gerrit.wikimedia.org/r/blubber/config"
)

func TestUserConfigValidation(t *testing.T) {
	t.Run("as", func(t *testing.T) {
		t.Run("ok", func(t *testing.T) {
			err := config.Validate(config.UserConfig{
				As: "foo-bar.baz",
			})

			assert.False(t, config.IsValidationError(err))
		})

		t.Run("optional", func(t *testing.T) {
			err := config.Validate(config.UserConfig{})

			assert.False(t, config.IsValidationError(err))
		})

		t.Run("no spaces", func(t *testing.T) {
			err := config.Validate(config.UserConfig{
				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.Validate(config.UserConfig{
				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.Validate(config.UserConfig{
				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)
			}
		})
	})
}