Skip to content

Commit c453326

Browse files
committed
fix: Correctly boxes max_file_size as an int and addresses the schema.Set type mismatch with restricted_file_extensions
1 parent b599ebb commit c453326

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

github/resource_github_organization_ruleset_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011
)
1112

1213
func TestGithubOrganizationRulesets(t *testing.T) {
@@ -589,7 +590,7 @@ func TestOrganizationPushRulesetSupport(t *testing.T) {
589590
},
590591
"max_file_size": []interface{}{
591592
map[string]interface{}{
592-
"max_file_size": float64(10485760), // 10MB
593+
"max_file_size": 10485760, // 10MB
593594
},
594595
},
595596
"max_file_path_length": []interface{}{
@@ -599,7 +600,9 @@ func TestOrganizationPushRulesetSupport(t *testing.T) {
599600
},
600601
"file_extension_restriction": []interface{}{
601602
map[string]interface{}{
602-
"restricted_file_extensions": []interface{}{".exe", ".bat", ".sh", ".ps1"},
603+
"restricted_file_extensions": schema.NewSet(schema.HashString, []interface{}{
604+
".exe", ".bat", ".sh", ".ps1",
605+
}),
603606
},
604607
},
605608
}

github/respository_rules_utils.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func expandRules(input []interface{}, org bool) []*github.RepositoryRule {
444444
// max_file_size rule
445445
if v, ok := rulesMap["max_file_size"].([]interface{}); ok && len(v) != 0 {
446446
maxFileSizeMap := v[0].(map[string]interface{})
447-
maxFileSize := int64(maxFileSizeMap["max_file_size"].(float64))
447+
maxFileSize := int64(maxFileSizeMap["max_file_size"].(int))
448448
params := &github.RuleMaxFileSizeParameters{
449449
MaxFileSize: maxFileSize,
450450
}
@@ -467,13 +467,19 @@ func expandRules(input []interface{}, org bool) []*github.RepositoryRule {
467467
if v, ok := rulesMap["file_extension_restriction"].([]interface{}); ok && len(v) != 0 {
468468
fileExtensionRestrictionMap := v[0].(map[string]interface{})
469469
restrictedFileExtensions := make([]string, 0)
470-
for _, extension := range fileExtensionRestrictionMap["restricted_file_extensions"].([]interface{}) {
470+
471+
// Handle schema.TypeSet
472+
extensionSet := fileExtensionRestrictionMap["restricted_file_extensions"].(*schema.Set)
473+
for _, extension := range extensionSet.List() {
471474
restrictedFileExtensions = append(restrictedFileExtensions, extension.(string))
472475
}
473-
params := &github.RuleFileExtensionRestrictionParameters{
474-
RestrictedFileExtensions: restrictedFileExtensions,
476+
477+
if len(restrictedFileExtensions) > 0 {
478+
params := &github.RuleFileExtensionRestrictionParameters{
479+
RestrictedFileExtensions: restrictedFileExtensions,
480+
}
481+
rulesSlice = append(rulesSlice, github.NewFileExtensionRestrictionRule(params))
475482
}
476-
rulesSlice = append(rulesSlice, github.NewFileExtensionRestrictionRule(params))
477483
}
478484

479485
return rulesSlice

github/respository_rules_utils_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/google/go-github/v67/github"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
)
910

1011
func TestFlattenRulesHandlesUnknownTypes(t *testing.T) {
@@ -255,7 +256,7 @@ func TestMaxFilePathLengthWithOtherRules(t *testing.T) {
255256
},
256257
"max_file_size": []interface{}{
257258
map[string]interface{}{
258-
"max_file_size": float64(1048576), // 1MB
259+
"max_file_size": 1048576, // 1MB
259260
},
260261
},
261262
}
@@ -349,7 +350,7 @@ func TestCompletePushRulesetSupport(t *testing.T) {
349350
},
350351
"max_file_size": []interface{}{
351352
map[string]interface{}{
352-
"max_file_size": float64(5242880), // 5MB
353+
"max_file_size": 5242880, // 5MB
353354
},
354355
},
355356
"max_file_path_length": []interface{}{
@@ -359,7 +360,9 @@ func TestCompletePushRulesetSupport(t *testing.T) {
359360
},
360361
"file_extension_restriction": []interface{}{
361362
map[string]interface{}{
362-
"restricted_file_extensions": []interface{}{".exe", ".bat", ".sh"},
363+
"restricted_file_extensions": schema.NewSet(schema.HashString, []interface{}{
364+
".exe", ".bat", ".sh",
365+
}),
363366
},
364367
},
365368
}

0 commit comments

Comments
 (0)