File: server_config_test.go

package info (click to toggle)
golang-google-firebase-go 4.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,552 kB
  • sloc: makefile: 21
file content (111 lines) | stat: -rw-r--r-- 2,693 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package remoteconfig

import "testing"

type configGetterTestCase struct {
	name           string
	key            string
	expectedString string
	expectedInt    int
	expectedBool   bool
	expectedFloat  float64
	expectedSource ValueSource
}

func getTestConfig() ServerConfig {
	config := ServerConfig{
		configValues: map[string]value{
			paramOne: {
				value:  valueOne,
				source: Default,
			},
			paramTwo: {
				value:  valueTwo,
				source: Remote,
			},
			paramThree: {
				value:  valueThree,
				source: Default,
			},
			paramFour: {
				value:  valueFour,
				source: Remote,
			},
		},
	}
	return config
}

func TestServerConfigGetters(t *testing.T) {
	config := getTestConfig()
	testCases := []configGetterTestCase{
		{
			name:           "Parameter Value : String, Default Source",
			key:            paramOne,
			expectedString: valueOne,
			expectedInt:    0,
			expectedBool:   false,
			expectedFloat:  0,
			expectedSource: Default,
		},
		{
			name:           "Parameter Value : JSON, Remote Source",
			key:            paramTwo,
			expectedString: valueTwo,
			expectedInt:    0,
			expectedBool:   false,
			expectedFloat:  0,
			expectedSource: Remote,
		},
		{
			name:           "Unknown Parameter Value",
			key:            "unknown_param",
			expectedString: "",
			expectedInt:    0,
			expectedBool:   false,
			expectedFloat:  0,
			expectedSource: Static,
		},
		{
			name:           "Parameter Value - Float, Default Source",
			key:            paramThree,
			expectedString: "123456789.123",
			expectedInt:    0,
			expectedBool:   false,
			expectedFloat:  123456789.123,
			expectedSource: Default,
		},
		{
			name:           "Parameter Value - Boolean, Remote Source",
			key:            paramFour,
			expectedString: "1",
			expectedInt:    1,
			expectedBool:   true,
			expectedFloat:  1,
			expectedSource: Remote,
		},
	}
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			if got := config.GetString(tc.key); got != tc.expectedString {
				t.Errorf("GetString(%q): got %q, want %q", tc.key, got, tc.expectedString)
			}

			if got := config.GetInt(tc.key); got != tc.expectedInt {
				t.Errorf("GetInt(%q): got %d, want %d", tc.key, got, tc.expectedInt)
			}

			if got := config.GetBoolean(tc.key); got != tc.expectedBool {
				t.Errorf("GetBoolean(%q): got %t, want %t", tc.key, got, tc.expectedBool)
			}

			if got := config.GetFloat(tc.key); got != tc.expectedFloat {
				t.Errorf("GetFloat(%q): got %f, want %f", tc.key, got, tc.expectedFloat)
			}

			if got := config.GetValueSource(tc.key); got != tc.expectedSource {
				t.Errorf("GetValueSource(%q): got %v, want %v", tc.key, got, tc.expectedSource)
			}
		})
	}
}