Skip to content

Commit 7cafc9a

Browse files
test: Add secret scanning marshal tests (#4252)
1 parent c207b27 commit 7cafc9a

1 file changed

Lines changed: 161 additions & 0 deletions

File tree

github/secret_scanning_test.go

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,167 @@ func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) {
607607
testJSONMarshal(t, u, want)
608608
}
609609

610+
func TestPushProtectionBypassRequest_Marshal(t *testing.T) {
611+
t.Parallel()
612+
testJSONMarshal(t, &PushProtectionBypassRequest{}, `{"reason": "", "placeholder_id": ""}`)
613+
614+
u := &PushProtectionBypassRequest{
615+
Reason: "will_fix_later",
616+
PlaceholderID: "bypass-123",
617+
}
618+
619+
want := `{
620+
"reason": "will_fix_later",
621+
"placeholder_id": "bypass-123"
622+
}`
623+
624+
testJSONMarshal(t, u, want)
625+
}
626+
627+
func TestPushProtectionBypass_Marshal(t *testing.T) {
628+
t.Parallel()
629+
testJSONMarshal(t, &PushProtectionBypass{}, `{"reason": "", "expire_at": null, "token_type": ""}`)
630+
631+
u := &PushProtectionBypass{
632+
Reason: "will_fix_later",
633+
ExpireAt: &Timestamp{referenceTime},
634+
TokenType: "github_token",
635+
}
636+
637+
want := `{
638+
"reason": "will_fix_later",
639+
"expire_at": ` + referenceTimeStr + `,
640+
"token_type": "github_token"
641+
}`
642+
643+
testJSONMarshal(t, u, want)
644+
}
645+
646+
func TestSecretsScan_Marshal(t *testing.T) {
647+
t.Parallel()
648+
testJSONMarshal(t, &SecretsScan{}, `{"type": "", "status": ""}`)
649+
650+
u := &SecretsScan{
651+
Type: "incremental",
652+
Status: "completed",
653+
CompletedAt: &Timestamp{referenceTime},
654+
StartedAt: &Timestamp{referenceTime},
655+
}
656+
657+
want := `{
658+
"type": "incremental",
659+
"status": "completed",
660+
"completed_at": ` + referenceTimeStr + `,
661+
"started_at": ` + referenceTimeStr + `
662+
}`
663+
664+
testJSONMarshal(t, u, want)
665+
}
666+
667+
func TestCustomPatternBackfillScan_Marshal(t *testing.T) {
668+
t.Parallel()
669+
testJSONMarshal(t, &CustomPatternBackfillScan{}, `{"type": "", "status": ""}`)
670+
671+
u := &CustomPatternBackfillScan{
672+
SecretsScan: SecretsScan{
673+
Type: "custom_pattern_backfill",
674+
Status: "completed",
675+
CompletedAt: &Timestamp{referenceTime},
676+
StartedAt: &Timestamp{referenceTime},
677+
},
678+
PatternSlug: Ptr("my-custom-pattern"),
679+
PatternScope: Ptr("repository"),
680+
}
681+
682+
want := `{
683+
"type": "custom_pattern_backfill",
684+
"status": "completed",
685+
"completed_at": ` + referenceTimeStr + `,
686+
"started_at": ` + referenceTimeStr + `,
687+
"pattern_slug": "my-custom-pattern",
688+
"pattern_scope": "repository"
689+
}`
690+
691+
testJSONMarshal(t, u, want)
692+
}
693+
694+
func TestSecretScanningScanHistory_Marshal(t *testing.T) {
695+
t.Parallel()
696+
testJSONMarshal(t, &SecretScanningScanHistory{}, `{}`)
697+
698+
u := &SecretScanningScanHistory{
699+
IncrementalScans: []*SecretsScan{
700+
{
701+
Type: "incremental",
702+
Status: "completed",
703+
CompletedAt: &Timestamp{referenceTime},
704+
StartedAt: &Timestamp{referenceTime},
705+
},
706+
},
707+
BackfillScans: []*SecretsScan{
708+
{
709+
Type: "backfill",
710+
Status: "in_progress",
711+
StartedAt: &Timestamp{referenceTime},
712+
},
713+
},
714+
PatternUpdateScans: []*SecretsScan{
715+
{
716+
Type: "pattern_update",
717+
Status: "pending",
718+
},
719+
},
720+
CustomPatternBackfillScans: []*CustomPatternBackfillScan{
721+
{
722+
SecretsScan: SecretsScan{
723+
Type: "custom_pattern_backfill",
724+
Status: "completed",
725+
CompletedAt: &Timestamp{referenceTime},
726+
StartedAt: &Timestamp{referenceTime},
727+
},
728+
PatternSlug: Ptr("my-custom-pattern"),
729+
PatternScope: Ptr("organization"),
730+
},
731+
},
732+
}
733+
734+
want := `{
735+
"incremental_scans": [
736+
{
737+
"type": "incremental",
738+
"status": "completed",
739+
"completed_at": ` + referenceTimeStr + `,
740+
"started_at": ` + referenceTimeStr + `
741+
}
742+
],
743+
"backfill_scans": [
744+
{
745+
"type": "backfill",
746+
"status": "in_progress",
747+
"started_at": ` + referenceTimeStr + `
748+
}
749+
],
750+
"pattern_update_scans": [
751+
{
752+
"type": "pattern_update",
753+
"status": "pending"
754+
}
755+
],
756+
"custom_pattern_backfill_scans": [
757+
{
758+
"type": "custom_pattern_backfill",
759+
"status": "completed",
760+
"completed_at": ` + referenceTimeStr + `,
761+
"started_at": ` + referenceTimeStr + `,
762+
"pattern_slug": "my-custom-pattern",
763+
"pattern_scope": "organization"
764+
}
765+
]
766+
}`
767+
768+
testJSONMarshal(t, u, want)
769+
}
770+
610771
func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) {
611772
t.Parallel()
612773
client, mux, _ := setup(t)

0 commit comments

Comments
 (0)