From af0890b848bbb341dd76686dd46500aa25180e13 Mon Sep 17 00:00:00 2001 From: Julien Midedji Date: Sun, 1 Oct 2023 16:03:02 +0200 Subject: [PATCH 1/2] Add tests for resource JSON marshaling - ActionVariable Helps #55 --- github/actions_variables_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/github/actions_variables_test.go b/github/actions_variables_test.go index 646da92b1e8..d855f61ae01 100644 --- a/github/actions_variables_test.go +++ b/github/actions_variables_test.go @@ -657,3 +657,29 @@ 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_repositories_ids": [1,2,3] + }`, referenceTimeStr, referenceTimeStr) + + testJSONMarshal(t, av, want) +} From 73ea7e5df0de021968fee9d2ae2dd221a0e49f1d Mon Sep 17 00:00:00 2001 From: Julien Midedji Date: Sun, 1 Oct 2023 18:59:23 +0200 Subject: [PATCH 2/2] Fix incorrect field name, correct mistake where dates were doubled quoted --- github/actions_variables_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/github/actions_variables_test.go b/github/actions_variables_test.go index d855f61ae01..a9f773c261e 100644 --- a/github/actions_variables_test.go +++ b/github/actions_variables_test.go @@ -674,12 +674,14 @@ func TestActionVariable_Marshal(t *testing.T) { want := fmt.Sprintf(`{ "name": "n", "value": "v", - "created_at": "%s", - "updated_at": "%s", + "created_at": %s, + "updated_at": %s, "visibility": "v", "selected_repositories_url": "s", - "selected_repositories_ids": [1,2,3] + "selected_repository_ids": [1,2,3] }`, referenceTimeStr, referenceTimeStr) + fmt.Println(want) + testJSONMarshal(t, av, want) }