Skip to content

Commit 8cd452b

Browse files
authored
Add json marshaling tests for action usage and OIDC types (#2944)
1 parent 25309f3 commit 8cd452b

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

github/actions_cache_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,133 @@ func TestActionsService_GetCacheUsageForEnterprise_notFound(t *testing.T) {
515515
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return %+v, want nil", caches)
516516
}
517517
}
518+
519+
func TestActionsCache_Marshal(t *testing.T) {
520+
testJSONMarshal(t, &ActionsCache{}, "{}")
521+
522+
u := &ActionsCache{
523+
ID: Int64(1),
524+
Ref: String("refAction"),
525+
Key: String("key1"),
526+
Version: String("alpha"),
527+
LastAccessedAt: &Timestamp{referenceTime},
528+
CreatedAt: &Timestamp{referenceTime},
529+
SizeInBytes: Int64(1),
530+
}
531+
532+
want := `{
533+
"id": 1,
534+
"ref": "refAction",
535+
"key": "key1",
536+
"version": "alpha",
537+
"last_accessed_at": ` + referenceTimeStr + `,
538+
"created_at": ` + referenceTimeStr + `,
539+
"size_in_bytes": 1
540+
}`
541+
542+
testJSONMarshal(t, u, want)
543+
}
544+
545+
func TestActionsCacheList_Marshal(t *testing.T) {
546+
testJSONMarshal(t, &ActionsCacheList{}, "{}")
547+
548+
u := &ActionsCacheList{
549+
TotalCount: 2,
550+
ActionsCaches: []*ActionsCache{
551+
{
552+
ID: Int64(1),
553+
Key: String("key1"),
554+
Version: String("alpha"),
555+
LastAccessedAt: &Timestamp{referenceTime},
556+
CreatedAt: &Timestamp{referenceTime},
557+
SizeInBytes: Int64(1),
558+
},
559+
{
560+
ID: Int64(2),
561+
Ref: String("refAction"),
562+
LastAccessedAt: &Timestamp{referenceTime},
563+
CreatedAt: &Timestamp{referenceTime},
564+
SizeInBytes: Int64(1),
565+
},
566+
},
567+
}
568+
want := `{
569+
"total_count": 2,
570+
"actions_caches": [{
571+
"id": 1,
572+
"key": "key1",
573+
"version": "alpha",
574+
"last_accessed_at": ` + referenceTimeStr + `,
575+
"created_at": ` + referenceTimeStr + `,
576+
"size_in_bytes": 1
577+
},
578+
{
579+
"id": 2,
580+
"ref": "refAction",
581+
"last_accessed_at": ` + referenceTimeStr + `,
582+
"created_at": ` + referenceTimeStr + `,
583+
"size_in_bytes": 1
584+
}]
585+
}`
586+
testJSONMarshal(t, u, want)
587+
}
588+
589+
func TestActionsCacheUsage_Marshal(t *testing.T) {
590+
testJSONMarshal(t, &ActionsCacheUsage{}, "{}")
591+
592+
u := &ActionsCacheUsage{
593+
FullName: "cache_usage1",
594+
ActiveCachesSizeInBytes: 2,
595+
ActiveCachesCount: 2,
596+
}
597+
598+
want := `{
599+
"full_name": "cache_usage1",
600+
"active_caches_size_in_bytes": 2,
601+
"active_caches_count": 2
602+
}`
603+
604+
testJSONMarshal(t, u, want)
605+
}
606+
607+
func TestActionsCacheUsageList_Marshal(t *testing.T) {
608+
testJSONMarshal(t, &ActionsCacheUsageList{}, "{}")
609+
610+
u := &ActionsCacheUsageList{
611+
TotalCount: 1,
612+
RepoCacheUsage: []*ActionsCacheUsage{
613+
{
614+
FullName: "cache_usage1",
615+
ActiveCachesSizeInBytes: 2,
616+
ActiveCachesCount: 2,
617+
},
618+
},
619+
}
620+
621+
want := `{
622+
"total_count": 1,
623+
"repository_cache_usages": [{
624+
"full_name": "cache_usage1",
625+
"active_caches_size_in_bytes": 2,
626+
"active_caches_count": 2
627+
}]
628+
}`
629+
630+
testJSONMarshal(t, u, want)
631+
}
632+
633+
func TestTotalCacheUsage_Marshal(t *testing.T) {
634+
testJSONMarshal(t, &TotalCacheUsage{}, "{}")
635+
636+
u := &TotalCacheUsage{
637+
TotalActiveCachesUsageSizeInBytes: 2,
638+
TotalActiveCachesCount: 2,
639+
}
640+
641+
want := `{
642+
"total_active_caches_size_in_bytes": 2,
643+
"total_active_caches_count": 2
644+
}`
645+
646+
testJSONMarshal(t, u, want)
647+
}

github/actions_oidc_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,21 @@ func TestActionService_SetRepoOIDCSubjectClaimCustomTemplateToDefault(t *testing
179179
return client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "o", "r", input)
180180
})
181181
}
182+
183+
func TestOIDCSubjectClaimCustomTemplate_Marshal(t *testing.T) {
184+
testJSONMarshal(t, &OIDCSubjectClaimCustomTemplate{}, "{}")
185+
186+
u := &OIDCSubjectClaimCustomTemplate{
187+
UseDefault: Bool(false),
188+
IncludeClaimKeys: []string{"s"},
189+
}
190+
191+
want := `{
192+
"use_default": false,
193+
"include_claim_keys": [
194+
"s"
195+
]
196+
}`
197+
198+
testJSONMarshal(t, u, want)
199+
}

0 commit comments

Comments
 (0)