-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_test.go
More file actions
349 lines (297 loc) · 10.7 KB
/
github_test.go
File metadata and controls
349 lines (297 loc) · 10.7 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// Code generated by Fern. DO NOT EDIT.
package generatorcli
import (
json "encoding/json"
assert "github.com/stretchr/testify/assert"
require "github.com/stretchr/testify/require"
testing "testing"
)
func TestSettersGitHubConfig(t *testing.T) {
t.Run("SetSourceDirectory", func(t *testing.T) {
obj := &GitHubConfig{}
var fernTestValueSourceDirectory string
obj.SetSourceDirectory(fernTestValueSourceDirectory)
assert.Equal(t, fernTestValueSourceDirectory, obj.SourceDirectory)
assert.NotNil(t, obj.explicitFields)
})
t.Run("SetUri", func(t *testing.T) {
obj := &GitHubConfig{}
var fernTestValueUri string
obj.SetUri(fernTestValueUri)
assert.Equal(t, fernTestValueUri, obj.Uri)
assert.NotNil(t, obj.explicitFields)
})
t.Run("SetToken", func(t *testing.T) {
obj := &GitHubConfig{}
var fernTestValueToken string
obj.SetToken(fernTestValueToken)
assert.Equal(t, fernTestValueToken, obj.Token)
assert.NotNil(t, obj.explicitFields)
})
t.Run("SetBranch", func(t *testing.T) {
obj := &GitHubConfig{}
var fernTestValueBranch *string
obj.SetBranch(fernTestValueBranch)
assert.Equal(t, fernTestValueBranch, obj.Branch)
assert.NotNil(t, obj.explicitFields)
})
}
func TestGettersGitHubConfig(t *testing.T) {
t.Run("GetSourceDirectory", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var expected string
obj.SourceDirectory = expected
// Act & Assert
assert.Equal(t, expected, obj.GetSourceDirectory(), "getter should return the property value")
})
t.Run("GetSourceDirectory_NilReceiver", func(t *testing.T) {
t.Parallel()
var obj *GitHubConfig
// Should not panic - getters should handle nil receiver gracefully
defer func() {
if r := recover(); r != nil {
t.Errorf("Getter panicked on nil receiver: %v", r)
}
}()
_ = obj.GetSourceDirectory() // Should return zero value
})
t.Run("GetUri", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var expected string
obj.Uri = expected
// Act & Assert
assert.Equal(t, expected, obj.GetUri(), "getter should return the property value")
})
t.Run("GetUri_NilReceiver", func(t *testing.T) {
t.Parallel()
var obj *GitHubConfig
// Should not panic - getters should handle nil receiver gracefully
defer func() {
if r := recover(); r != nil {
t.Errorf("Getter panicked on nil receiver: %v", r)
}
}()
_ = obj.GetUri() // Should return zero value
})
t.Run("GetToken", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var expected string
obj.Token = expected
// Act & Assert
assert.Equal(t, expected, obj.GetToken(), "getter should return the property value")
})
t.Run("GetToken_NilReceiver", func(t *testing.T) {
t.Parallel()
var obj *GitHubConfig
// Should not panic - getters should handle nil receiver gracefully
defer func() {
if r := recover(); r != nil {
t.Errorf("Getter panicked on nil receiver: %v", r)
}
}()
_ = obj.GetToken() // Should return zero value
})
t.Run("GetBranch", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var expected *string
obj.Branch = expected
// Act & Assert
assert.Equal(t, expected, obj.GetBranch(), "getter should return the property value")
})
t.Run("GetBranch_NilValue", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
obj.Branch = nil
// Act & Assert
assert.Nil(t, obj.GetBranch(), "getter should return nil when property is nil")
})
t.Run("GetBranch_NilReceiver", func(t *testing.T) {
t.Parallel()
var obj *GitHubConfig
// Should not panic - getters should handle nil receiver gracefully
defer func() {
if r := recover(); r != nil {
t.Errorf("Getter panicked on nil receiver: %v", r)
}
}()
_ = obj.GetBranch() // Should return zero value
})
}
func TestSettersMarkExplicitGitHubConfig(t *testing.T) {
t.Run("SetSourceDirectory_MarksExplicit", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var fernTestValueSourceDirectory string
// Act
obj.SetSourceDirectory(fernTestValueSourceDirectory)
// Assert - object with explicitly set field can be marshaled/unmarshaled
bytes, err := json.Marshal(obj)
require.NoError(t, err, "marshaling should succeed for test setup")
// This test ensures JSON marshaling and unmarshaling succeed when the field has a zero/nil value
// Detect if marshaled JSON is an object or primitive to use correct unmarshal target
if len(bytes) > 0 && bytes[0] == '{' {
// JSON object - unmarshal into map
var unmarshaled map[string]interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
} else {
// JSON primitive (string, number, boolean, null) - unmarshal into interface{}
var unmarshaled interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
}
// Note: This does not explicitly assert the presence of a specific JSON field
// It verifies that setting a field via setter allows successful JSON round-trip
})
t.Run("SetUri_MarksExplicit", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var fernTestValueUri string
// Act
obj.SetUri(fernTestValueUri)
// Assert - object with explicitly set field can be marshaled/unmarshaled
bytes, err := json.Marshal(obj)
require.NoError(t, err, "marshaling should succeed for test setup")
// This test ensures JSON marshaling and unmarshaling succeed when the field has a zero/nil value
// Detect if marshaled JSON is an object or primitive to use correct unmarshal target
if len(bytes) > 0 && bytes[0] == '{' {
// JSON object - unmarshal into map
var unmarshaled map[string]interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
} else {
// JSON primitive (string, number, boolean, null) - unmarshal into interface{}
var unmarshaled interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
}
// Note: This does not explicitly assert the presence of a specific JSON field
// It verifies that setting a field via setter allows successful JSON round-trip
})
t.Run("SetToken_MarksExplicit", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var fernTestValueToken string
// Act
obj.SetToken(fernTestValueToken)
// Assert - object with explicitly set field can be marshaled/unmarshaled
bytes, err := json.Marshal(obj)
require.NoError(t, err, "marshaling should succeed for test setup")
// This test ensures JSON marshaling and unmarshaling succeed when the field has a zero/nil value
// Detect if marshaled JSON is an object or primitive to use correct unmarshal target
if len(bytes) > 0 && bytes[0] == '{' {
// JSON object - unmarshal into map
var unmarshaled map[string]interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
} else {
// JSON primitive (string, number, boolean, null) - unmarshal into interface{}
var unmarshaled interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
}
// Note: This does not explicitly assert the presence of a specific JSON field
// It verifies that setting a field via setter allows successful JSON round-trip
})
t.Run("SetBranch_MarksExplicit", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
var fernTestValueBranch *string
// Act
obj.SetBranch(fernTestValueBranch)
// Assert - object with explicitly set field can be marshaled/unmarshaled
bytes, err := json.Marshal(obj)
require.NoError(t, err, "marshaling should succeed for test setup")
// This test ensures JSON marshaling and unmarshaling succeed when the field has a zero/nil value
// Detect if marshaled JSON is an object or primitive to use correct unmarshal target
if len(bytes) > 0 && bytes[0] == '{' {
// JSON object - unmarshal into map
var unmarshaled map[string]interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
} else {
// JSON primitive (string, number, boolean, null) - unmarshal into interface{}
var unmarshaled interface{}
err = json.Unmarshal(bytes, &unmarshaled)
require.NoError(t, err, "unmarshaling should succeed for test verification")
}
// Note: This does not explicitly assert the presence of a specific JSON field
// It verifies that setting a field via setter allows successful JSON round-trip
})
}
func TestJSONMarshalingGitHubConfig(t *testing.T) {
t.Run("MarshalUnmarshal", func(t *testing.T) {
t.Parallel()
// Arrange
obj := &GitHubConfig{}
// Act - Marshal to JSON
data, err := json.Marshal(obj)
require.NoError(t, err, "marshaling should succeed")
assert.NotNil(t, data, "marshaled data should not be nil")
assert.NotEmpty(t, data, "marshaled data should not be empty")
// Unmarshal back and verify round-trip
var unmarshaled GitHubConfig
err = json.Unmarshal(data, &unmarshaled)
assert.NoError(t, err, "round-trip unmarshal should succeed")
})
t.Run("UnmarshalInvalidJSON", func(t *testing.T) {
t.Parallel()
var obj GitHubConfig
err := json.Unmarshal([]byte(`{invalid json}`), &obj)
assert.Error(t, err, "unmarshaling invalid JSON should return an error")
})
t.Run("UnmarshalEmptyObject", func(t *testing.T) {
t.Parallel()
var obj GitHubConfig
err := json.Unmarshal([]byte(`{}`), &obj)
assert.NoError(t, err, "unmarshaling empty object should succeed")
})
}
func TestStringGitHubConfig(t *testing.T) {
t.Run("StringMethod", func(t *testing.T) {
t.Parallel()
obj := &GitHubConfig{}
result := obj.String()
assert.NotEmpty(t, result, "String() should return a non-empty representation")
})
t.Run("StringMethod_NilReceiver", func(t *testing.T) {
t.Parallel()
var obj *GitHubConfig
result := obj.String()
assert.Equal(t, "<nil>", result, "String() should return <nil> for nil receiver")
})
}
func TestExtraPropertiesGitHubConfig(t *testing.T) {
t.Run("GetExtraProperties", func(t *testing.T) {
t.Parallel()
obj := &GitHubConfig{}
// Should not panic when calling GetExtraProperties()
defer func() {
if r := recover(); r != nil {
t.Errorf("GetExtraProperties() panicked: %v", r)
}
}()
extraProps := obj.GetExtraProperties()
// Result can be nil or an empty/non-empty map
_ = extraProps
})
t.Run("GetExtraProperties_NilReceiver", func(t *testing.T) {
t.Parallel()
var obj *GitHubConfig
extraProps := obj.GetExtraProperties()
assert.Nil(t, extraProps, "nil receiver should return nil without panicking")
})
}