|
1 | 1 | package generator_test |
2 | 2 |
|
3 | | -// func TestParseTokens(t *testing.T) { |
4 | | -// ttests := map[string]struct { |
5 | | -// config generator.GenVarsConfig |
6 | | -// rawToken string |
7 | | -// expect generator.TokenConfigVars |
8 | | -// }{ |
9 | | -// "role, version specified": { |
10 | | -// *generator.NewConfig(), |
11 | | -// `FOO://basjh/dskjuds/123|d88[role:arn:aws:iam::1111111:role/i-orchestration,version:1082313]`, |
12 | | -// generator.TokenConfigVars{ |
13 | | -// Token: `FOO://basjh/dskjuds/123|d88`, |
14 | | -// Role: `arn:aws:iam::1111111:role/i-orchestration`, |
15 | | -// Version: `1082313`, |
16 | | -// }, |
17 | | -// }, |
18 | | -// "version, role specified": { |
19 | | -// *generator.NewConfig(), |
20 | | -// `FOO://basjh/dskjuds/123|d88[version:1082313,role:arn:aws:iam::1111111:role/i-orchestration]`, |
21 | | -// generator.TokenConfigVars{ |
22 | | -// Token: `FOO://basjh/dskjuds/123|d88`, |
23 | | -// Role: `arn:aws:iam::1111111:role/i-orchestration`, |
24 | | -// Version: `1082313`, |
25 | | -// }, |
26 | | -// }, |
27 | | -// "version only specified": { |
28 | | -// *generator.NewConfig(), |
29 | | -// `FOO://basjh/dskjuds/123|d88[version:1082313]`, |
30 | | -// generator.TokenConfigVars{ |
31 | | -// Token: `FOO://basjh/dskjuds/123|d88`, |
32 | | -// Role: ``, |
33 | | -// Version: `1082313`, |
34 | | -// }, |
35 | | -// }, |
36 | | -// "role only specified": { |
37 | | -// *generator.NewConfig(), |
38 | | -// `FOO://basjh/dskjuds/123|d88[role:arn:aws:iam::1111111:role/i-orchestration]`, |
39 | | -// generator.TokenConfigVars{ |
40 | | -// Token: `FOO://basjh/dskjuds/123|d88`, |
41 | | -// Role: `arn:aws:iam::1111111:role/i-orchestration`, |
42 | | -// Version: ``, |
43 | | -// }, |
44 | | -// }, |
45 | | -// "no additional config specified": { |
46 | | -// *generator.NewConfig(), |
47 | | -// `FOO://basjh/dskjuds/123|d88`, |
48 | | -// generator.TokenConfigVars{ |
49 | | -// Token: `FOO://basjh/dskjuds/123|d88`, |
50 | | -// Role: ``, |
51 | | -// Version: ``, |
52 | | -// }, |
53 | | -// }, |
54 | | -// "additional config specified but empty": { |
55 | | -// *generator.NewConfig(), |
56 | | -// `FOO://basjh/dskjuds/123[]`, |
57 | | -// generator.TokenConfigVars{ |
58 | | -// Token: `FOO://basjh/dskjuds/123`, |
59 | | -// Role: ``, |
60 | | -// Version: ``, |
61 | | -// }, |
62 | | -// }, |
63 | | -// } |
64 | | -// for name, tt := range ttests { |
65 | | -// t.Run(name, func(t *testing.T) { |
66 | | -// got := tt.config.ParseTokenVars(tt.rawToken) |
67 | | -// if got.Role != tt.expect.Role { |
68 | | -// t.Errorf(testutils.TestPhraseWithContext, "role incorrect", got.Role, tt.expect.Role) |
69 | | -// } |
70 | | -// if got.Version != tt.expect.Version { |
71 | | -// t.Errorf(testutils.TestPhraseWithContext, "version incorrect", got.Version, tt.expect.Version) |
72 | | -// } |
73 | | -// if got.Token != tt.expect.Token { |
74 | | -// t.Errorf(testutils.TestPhraseWithContext, "token incorrect", got.Token, tt.expect.Token) |
75 | | -// } |
76 | | -// }) |
77 | | -// } |
78 | | -// } |
| 3 | +import ( |
| 4 | + "testing" |
79 | 5 |
|
80 | | -// func Test_MarshalMetadata_with_label_struct_succeeds(t *testing.T) { |
81 | | -// type labelMeta struct { |
82 | | -// Label string `json:"label"` |
83 | | -// } |
| 6 | + "github.com/dnitsch/configmanager/internal/testutils" |
| 7 | + "github.com/dnitsch/configmanager/pkg/generator" |
| 8 | +) |
84 | 9 |
|
85 | | -// ttests := map[string]struct { |
86 | | -// config *generator.GenVarsConfig |
87 | | -// rawToken string |
88 | | -// wantVal any |
89 | | -// }{ |
90 | | -// "when provider expects label on token and label exists": { |
91 | | -// generator.NewConfig(), |
92 | | -// `FOO://basjh/dskjuds/123|d88[label=dev]`, |
93 | | -// "dev", |
94 | | -// }, |
95 | | -// "when provider expects label on token and label does not exist": { |
96 | | -// generator.NewConfig(), |
97 | | -// `FOO://basjh/dskjuds/123|d88[someother=dev]`, |
98 | | -// "", |
99 | | -// }, |
100 | | -// "no metadata found": { |
101 | | -// generator.NewConfig(), |
102 | | -// `FOO://basjh/dskjuds/123|d88`, |
103 | | -// "", |
104 | | -// }, |
105 | | -// "no metadata found incorrect marker placement": { |
106 | | -// generator.NewConfig(), |
107 | | -// `FOO://basjh/dskjuds/123|d88]asdas=bar[`, |
108 | | -// "", |
109 | | -// }, |
110 | | -// } |
111 | | -// for name, tt := range ttests { |
112 | | -// t.Run(name, func(t *testing.T) { |
113 | | -// inputTyp := &labelMeta{} |
114 | | -// got := tt.config.ParseMetadata(tt.rawToken, inputTyp) |
115 | | -// if got == nil { |
116 | | -// t.Errorf("got <nil>, wanted: %v\n", inputTyp) |
117 | | -// } |
| 10 | +func Test_MarshalMetadata_with_label_struct_succeeds(t *testing.T) { |
| 11 | + type labelMeta struct { |
| 12 | + Label string `json:"label"` |
| 13 | + } |
118 | 14 |
|
119 | | -// gotTyp := got.(*labelMeta) |
| 15 | + ttests := map[string]struct { |
| 16 | + config *generator.GenVarsConfig |
| 17 | + rawToken string |
| 18 | + wantLabel string |
| 19 | + wantToken string |
| 20 | + }{ |
| 21 | + "when provider expects label on token and label exists": { |
| 22 | + generator.NewConfig(), |
| 23 | + `FOO://basjh/dskjuds/123|d88[label=dev]`, |
| 24 | + "dev", |
| 25 | + "FOO://basjh/dskjuds/123|d88", |
| 26 | + }, |
| 27 | + "when provider expects label on token and label does not exist": { |
| 28 | + generator.NewConfig(), |
| 29 | + `FOO://basjh/dskjuds/123|d88[someother=dev]`, |
| 30 | + "", |
| 31 | + "FOO://basjh/dskjuds/123|d88", |
| 32 | + }, |
| 33 | + "no metadata found": { |
| 34 | + generator.NewConfig(), |
| 35 | + `FOO://basjh/dskjuds/123|d88`, |
| 36 | + "", |
| 37 | + "FOO://basjh/dskjuds/123|d88", |
| 38 | + }, |
| 39 | + "no metadata found incorrect marker placement": { |
| 40 | + generator.NewConfig(), |
| 41 | + `FOO://basjh/dskjuds/123|d88]asdas=bar[`, |
| 42 | + "", |
| 43 | + "FOO://basjh/dskjuds/123|d88]asdas=bar[", |
| 44 | + }, |
| 45 | + "no metadata found incorrect marker placement and no key separator": { |
| 46 | + generator.NewConfig(), |
| 47 | + `FOO://basjh/dskjuds/123]asdas=bar[`, |
| 48 | + "", |
| 49 | + "FOO://basjh/dskjuds/123]asdas=bar[", |
| 50 | + }, |
| 51 | + "no end found incorrect marker placement and no key separator": { |
| 52 | + generator.NewConfig(), |
| 53 | + `FOO://basjh/dskjuds/123[asdas=bar`, |
| 54 | + "", |
| 55 | + "FOO://basjh/dskjuds/123[asdas=bar", |
| 56 | + }, |
| 57 | + "no start found incorrect marker placement and no key separator": { |
| 58 | + generator.NewConfig(), |
| 59 | + `FOO://basjh/dskjuds/123]asdas=bar]`, |
| 60 | + "", |
| 61 | + "FOO://basjh/dskjuds/123]asdas=bar]", |
| 62 | + }, |
| 63 | + } |
| 64 | + for name, tt := range ttests { |
| 65 | + t.Run(name, func(t *testing.T) { |
| 66 | + inputTyp := &labelMeta{} |
| 67 | + got := generator.ParseMetadata(tt.rawToken, inputTyp) |
120 | 68 |
|
121 | | -// if gotTyp.Label != tt.wantVal { |
122 | | -// t.Errorf("got %v, wanted: %v\n", gotTyp, inputTyp) |
123 | | -// } |
124 | | -// }) |
125 | | -// } |
126 | | -// } |
| 69 | + if got != tt.wantToken { |
| 70 | + t.Errorf(testutils.TestPhraseWithContext, "Token does not match", got, tt.wantToken) |
| 71 | + } |
127 | 72 |
|
128 | | -// func Test_MarshalMetadata_with_label_struct_fails_with_nil_pointer(t *testing.T) { |
129 | | -// got := generator.NewConfig().ParseMetadata(`FOO://basjh/dskjuds/123|d88`, nil) |
130 | | -// if got != nil { |
131 | | -// t.Errorf("got %v, wanted:<nil>\n", got) |
132 | | -// } |
133 | | - |
134 | | -// } |
| 73 | + if inputTyp.Label != tt.wantLabel { |
| 74 | + t.Errorf(testutils.TestPhraseWithContext, "Metadata Label does not match", inputTyp.Label, tt.wantLabel) |
| 75 | + } |
| 76 | + }) |
| 77 | + } |
| 78 | +} |
0 commit comments