Skip to content

Commit 050b379

Browse files
sagar23sjgmlewis
authored andcommitted
Add test cases for JSON resource marshalling (#1910)
1 parent 684b1c9 commit 050b379

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

github/actions_secrets_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,121 @@ func TestActionsService_DeleteEnvSecret(t *testing.T) {
810810
return client.Actions.DeleteEnvSecret(ctx, 1, "r", "secret")
811811
})
812812
}
813+
814+
func TestPublicKey_Marshal(t *testing.T) {
815+
testJSONMarshal(t, &PublicKey{}, "{}")
816+
817+
u := &PublicKey{
818+
KeyID: String("kid"),
819+
Key: String("k"),
820+
}
821+
822+
want := `{
823+
"key_id": "kid",
824+
"key": "k"
825+
}`
826+
827+
testJSONMarshal(t, u, want)
828+
}
829+
830+
func TestSecret_Marshal(t *testing.T) {
831+
testJSONMarshal(t, &Secret{}, "{}")
832+
833+
u := &Secret{
834+
Name: "n",
835+
CreatedAt: Timestamp{referenceTime},
836+
UpdatedAt: Timestamp{referenceTime},
837+
Visibility: "v",
838+
SelectedRepositoriesURL: "s",
839+
}
840+
841+
want := `{
842+
"name": "n",
843+
"created_at": ` + referenceTimeStr + `,
844+
"updated_at": ` + referenceTimeStr + `,
845+
"visibility": "v",
846+
"selected_repositories_url": "s"
847+
}`
848+
849+
testJSONMarshal(t, u, want)
850+
}
851+
852+
func TestSecrets_Marshal(t *testing.T) {
853+
testJSONMarshal(t, &Secrets{}, "{}")
854+
855+
u := &Secrets{
856+
TotalCount: 1,
857+
Secrets: []*Secret{
858+
{
859+
Name: "n",
860+
CreatedAt: Timestamp{referenceTime},
861+
UpdatedAt: Timestamp{referenceTime},
862+
Visibility: "v",
863+
SelectedRepositoriesURL: "s"},
864+
},
865+
}
866+
867+
want := `{
868+
"total_count": 1,
869+
"secrets": [
870+
{
871+
"name": "n",
872+
"created_at": ` + referenceTimeStr + `,
873+
"updated_at": ` + referenceTimeStr + `,
874+
"visibility": "v",
875+
"selected_repositories_url": "s"
876+
}
877+
]
878+
}`
879+
880+
testJSONMarshal(t, u, want)
881+
}
882+
883+
func TestEncryptedSecret_Marshal(t *testing.T) {
884+
testJSONMarshal(t, &EncryptedSecret{}, "{}")
885+
886+
u := &EncryptedSecret{
887+
Name: "n",
888+
KeyID: "kid",
889+
EncryptedValue: "e",
890+
Visibility: "v",
891+
SelectedRepositoryIDs: []int64{1},
892+
}
893+
894+
want := `{
895+
"key_id": "kid",
896+
"encrypted_value": "e",
897+
"visibility": "v",
898+
"selected_repository_ids": [1]
899+
}`
900+
901+
testJSONMarshal(t, u, want)
902+
}
903+
904+
func TestSelectedReposList_Marshal(t *testing.T) {
905+
testJSONMarshal(t, &SelectedReposList{}, "{}")
906+
907+
u := &SelectedReposList{
908+
TotalCount: Int(1),
909+
Repositories: []*Repository{
910+
{
911+
ID: Int64(1),
912+
URL: String("u"),
913+
Name: String("n"),
914+
},
915+
},
916+
}
917+
918+
want := `{
919+
"total_count": 1,
920+
"repositories": [
921+
{
922+
"id": 1,
923+
"url": "u",
924+
"name": "n"
925+
}
926+
]
927+
}`
928+
929+
testJSONMarshal(t, u, want)
930+
}

0 commit comments

Comments
 (0)