Skip to content

Commit

Permalink
Merge branch 'master' into addRepositorySecurityAdvisoryAPIs
Browse files Browse the repository at this point in the history
  • Loading branch information
anishrajan25 authored Oct 2, 2023
2 parents 3c72dec + 8cd452b commit 8b0c9c9
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 0 deletions.
130 changes: 130 additions & 0 deletions github/actions_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,133 @@ func TestActionsService_GetCacheUsageForEnterprise_notFound(t *testing.T) {
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return %+v, want nil", caches)
}
}

func TestActionsCache_Marshal(t *testing.T) {
testJSONMarshal(t, &ActionsCache{}, "{}")

u := &ActionsCache{
ID: Int64(1),
Ref: String("refAction"),
Key: String("key1"),
Version: String("alpha"),
LastAccessedAt: &Timestamp{referenceTime},
CreatedAt: &Timestamp{referenceTime},
SizeInBytes: Int64(1),
}

want := `{
"id": 1,
"ref": "refAction",
"key": "key1",
"version": "alpha",
"last_accessed_at": ` + referenceTimeStr + `,
"created_at": ` + referenceTimeStr + `,
"size_in_bytes": 1
}`

testJSONMarshal(t, u, want)
}

func TestActionsCacheList_Marshal(t *testing.T) {
testJSONMarshal(t, &ActionsCacheList{}, "{}")

u := &ActionsCacheList{
TotalCount: 2,
ActionsCaches: []*ActionsCache{
{
ID: Int64(1),
Key: String("key1"),
Version: String("alpha"),
LastAccessedAt: &Timestamp{referenceTime},
CreatedAt: &Timestamp{referenceTime},
SizeInBytes: Int64(1),
},
{
ID: Int64(2),
Ref: String("refAction"),
LastAccessedAt: &Timestamp{referenceTime},
CreatedAt: &Timestamp{referenceTime},
SizeInBytes: Int64(1),
},
},
}
want := `{
"total_count": 2,
"actions_caches": [{
"id": 1,
"key": "key1",
"version": "alpha",
"last_accessed_at": ` + referenceTimeStr + `,
"created_at": ` + referenceTimeStr + `,
"size_in_bytes": 1
},
{
"id": 2,
"ref": "refAction",
"last_accessed_at": ` + referenceTimeStr + `,
"created_at": ` + referenceTimeStr + `,
"size_in_bytes": 1
}]
}`
testJSONMarshal(t, u, want)
}

func TestActionsCacheUsage_Marshal(t *testing.T) {
testJSONMarshal(t, &ActionsCacheUsage{}, "{}")

u := &ActionsCacheUsage{
FullName: "cache_usage1",
ActiveCachesSizeInBytes: 2,
ActiveCachesCount: 2,
}

want := `{
"full_name": "cache_usage1",
"active_caches_size_in_bytes": 2,
"active_caches_count": 2
}`

testJSONMarshal(t, u, want)
}

func TestActionsCacheUsageList_Marshal(t *testing.T) {
testJSONMarshal(t, &ActionsCacheUsageList{}, "{}")

u := &ActionsCacheUsageList{
TotalCount: 1,
RepoCacheUsage: []*ActionsCacheUsage{
{
FullName: "cache_usage1",
ActiveCachesSizeInBytes: 2,
ActiveCachesCount: 2,
},
},
}

want := `{
"total_count": 1,
"repository_cache_usages": [{
"full_name": "cache_usage1",
"active_caches_size_in_bytes": 2,
"active_caches_count": 2
}]
}`

testJSONMarshal(t, u, want)
}

func TestTotalCacheUsage_Marshal(t *testing.T) {
testJSONMarshal(t, &TotalCacheUsage{}, "{}")

u := &TotalCacheUsage{
TotalActiveCachesUsageSizeInBytes: 2,
TotalActiveCachesCount: 2,
}

want := `{
"total_active_caches_size_in_bytes": 2,
"total_active_caches_count": 2
}`

testJSONMarshal(t, u, want)
}
18 changes: 18 additions & 0 deletions github/actions_oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,21 @@ func TestActionService_SetRepoOIDCSubjectClaimCustomTemplateToDefault(t *testing
return client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "o", "r", input)
})
}

func TestOIDCSubjectClaimCustomTemplate_Marshal(t *testing.T) {
testJSONMarshal(t, &OIDCSubjectClaimCustomTemplate{}, "{}")

u := &OIDCSubjectClaimCustomTemplate{
UseDefault: Bool(false),
IncludeClaimKeys: []string{"s"},
}

want := `{
"use_default": false,
"include_claim_keys": [
"s"
]
}`

testJSONMarshal(t, u, want)
}
28 changes: 28 additions & 0 deletions github/actions_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,31 @@ func TestActionsService_DeleteEnvVariable(t *testing.T) {
return client.Actions.DeleteEnvVariable(ctx, 1, "r", "variable")
})
}

func TestActionVariable_Marshal(t *testing.T) {
testJSONMarshal(t, &ActionsVariable{}, "{}")

av := &ActionsVariable{
Name: "n",
Value: "v",
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
Visibility: String("v"),
SelectedRepositoriesURL: String("s"),
SelectedRepositoryIDs: &SelectedRepoIDs{1, 2, 3},
}

want := fmt.Sprintf(`{
"name": "n",
"value": "v",
"created_at": %s,
"updated_at": %s,
"visibility": "v",
"selected_repositories_url": "s",
"selected_repository_ids": [1,2,3]
}`, referenceTimeStr, referenceTimeStr)

fmt.Println(want)

testJSONMarshal(t, av, want)
}

0 comments on commit 8b0c9c9

Please sign in to comment.