|
1 | 1 | package oauth2cli |
2 | | - |
3 | | -import ( |
4 | | - "testing" |
5 | | - |
6 | | - "github.com/google/go-cmp/cmp" |
7 | | -) |
8 | | - |
9 | | -func TestConfig_populateDeprecatedFields(t *testing.T) { |
10 | | - t.Run("DefaultValue", func(t *testing.T) { |
11 | | - var cfg Config |
12 | | - cfg.populateDeprecatedFields() |
13 | | - var want []string |
14 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
15 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
16 | | - } |
17 | | - }) |
18 | | - |
19 | | - t.Run("AddressOnly", func(t *testing.T) { |
20 | | - cfg := Config{ |
21 | | - LocalServerAddress: "0.0.0.0", |
22 | | - } |
23 | | - cfg.populateDeprecatedFields() |
24 | | - var want []string |
25 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
26 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
27 | | - } |
28 | | - }) |
29 | | - |
30 | | - t.Run("SinglePort", func(t *testing.T) { |
31 | | - cfg := Config{ |
32 | | - LocalServerPort: []int{8000}, |
33 | | - } |
34 | | - cfg.populateDeprecatedFields() |
35 | | - want := []string{"127.0.0.1:8000"} |
36 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
37 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
38 | | - } |
39 | | - }) |
40 | | - |
41 | | - t.Run("SinglePortWithAddress", func(t *testing.T) { |
42 | | - cfg := Config{ |
43 | | - LocalServerAddress: "0.0.0.0", |
44 | | - LocalServerPort: []int{8000}, |
45 | | - } |
46 | | - cfg.populateDeprecatedFields() |
47 | | - want := []string{"0.0.0.0:8000"} |
48 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
49 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
50 | | - } |
51 | | - }) |
52 | | - |
53 | | - t.Run("MultiplePort", func(t *testing.T) { |
54 | | - cfg := Config{ |
55 | | - LocalServerPort: []int{8000, 18000}, |
56 | | - } |
57 | | - cfg.populateDeprecatedFields() |
58 | | - want := []string{"127.0.0.1:8000", "127.0.0.1:18000"} |
59 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
60 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
61 | | - } |
62 | | - }) |
63 | | - |
64 | | - t.Run("MultiplePortWithAddress", func(t *testing.T) { |
65 | | - cfg := Config{ |
66 | | - LocalServerAddress: "0.0.0.0", |
67 | | - LocalServerPort: []int{8000, 18000}, |
68 | | - } |
69 | | - cfg.populateDeprecatedFields() |
70 | | - want := []string{"0.0.0.0:8000", "0.0.0.0:18000"} |
71 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
72 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
73 | | - } |
74 | | - }) |
75 | | - |
76 | | - t.Run("PreserveOriginalValue", func(t *testing.T) { |
77 | | - t.Run("DefaultValue", func(t *testing.T) { |
78 | | - cfg := Config{ |
79 | | - LocalServerBindAddress: []string{"127.0.0.1:10000"}, |
80 | | - } |
81 | | - cfg.populateDeprecatedFields() |
82 | | - want := []string{"127.0.0.1:10000"} |
83 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
84 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
85 | | - } |
86 | | - }) |
87 | | - |
88 | | - t.Run("SinglePort", func(t *testing.T) { |
89 | | - cfg := Config{ |
90 | | - LocalServerBindAddress: []string{"127.0.0.1:10000"}, |
91 | | - LocalServerPort: []int{8000}, |
92 | | - } |
93 | | - cfg.populateDeprecatedFields() |
94 | | - want := []string{"127.0.0.1:10000", "127.0.0.1:8000"} |
95 | | - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { |
96 | | - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) |
97 | | - } |
98 | | - }) |
99 | | - }) |
100 | | -} |
0 commit comments