From 4887dcc1e958b4419f336fcb8eecef2264bc503f Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Tue, 13 Jul 2021 01:04:37 +0530 Subject: [PATCH] Resources Covered : - GetAuditLogOptions - HookConfig - AuditEntry --- github/orgs_audit_log_test.go | 184 ++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go index 34690104b2b..1121ffd2d22 100644 --- a/github/orgs_audit_log_test.go +++ b/github/orgs_audit_log_test.go @@ -112,3 +112,187 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { }) } + +func TestGetAuditLogOptions_Marshal(t *testing.T) { + testJSONMarshal(t, &GetAuditLogOptions{}, "{}") + + u := &GetAuditLogOptions{ + Phrase: String("p"), + Include: String("i"), + Order: String("o"), + ListCursorOptions: ListCursorOptions{ + Page: "p", + PerPage: 1, + After: "a", + Before: "b", + }, + } + + want := `{ + "phrase": "p", + "include": "i", + "order": "o", + "Page": "p", + "PerPage": 1, + "After": "a", + "Before": "b" + }` + + testJSONMarshal(t, u, want) +} + +func TestHookConfig_Marshal(t *testing.T) { + testJSONMarshal(t, &HookConfig{}, "{}") + + u := &HookConfig{ + ContentType: String("ct"), + InsecureSSL: String("ct"), + URL: String("url"), + } + + want := `{ + "content_type": "ct", + "insecure_ssl": "ct", + "url": "url" + }` + + testJSONMarshal(t, u, want) +} + +func TestAuditEntry_Marshal(t *testing.T) { + testJSONMarshal(t, &AuditEntry{}, "{}") + + u := &AuditEntry{ + Action: String("a"), + Active: Bool(false), + ActiveWas: Bool(false), + Actor: String("ac"), + BlockedUser: String("bu"), + Business: String("b"), + CancelledAt: &Timestamp{referenceTime}, + CompletedAt: &Timestamp{referenceTime}, + Conclusion: String("c"), + Config: &HookConfig{URL: String("s")}, + ConfigWas: &HookConfig{URL: String("s")}, + ContentType: String("ct"), + CreatedAt: &Timestamp{referenceTime}, + DeployKeyFingerprint: String("dkf"), + DocumentID: String("did"), + Emoji: String("e"), + EnvironmentName: String("en"), + Event: String("e"), + Events: []string{"s"}, + EventsWere: []string{"s"}, + Explanation: String("e"), + Fingerprint: String("f"), + HeadBranch: String("hb"), + HeadSHA: String("hsha"), + HookID: Int64(1), + IsHostedRunner: Bool(false), + JobName: String("jn"), + LimitedAvailability: Bool(false), + Message: String("m"), + Name: String("n"), + OldUser: String("ou"), + OpenSSHPublicKey: String("osshpk"), + Org: String("o"), + PreviousVisibility: String("pv"), + ReadOnly: String("ro"), + Repo: String("r"), + Repository: String("repo"), + RepositoryPublic: Bool(false), + RunnerGroupID: String("rgid"), + RunnerGroupName: String("rgn"), + RunnerID: String("rid"), + RunnerLabels: []string{"s"}, + RunnerName: String("rn"), + SecretsPassed: []string{"s"}, + SourceVersion: String("sv"), + StartedAt: &Timestamp{referenceTime}, + TargetLogin: String("tl"), + TargetVersion: String("tv"), + Team: String("t"), + Timestamp: &Timestamp{referenceTime}, + TransportProtocolName: String("tpn"), + TransportProtocol: Int(1), + TriggerID: Int64(1), + User: String("u"), + Visibility: String("v"), + WorkflowID: Int64(1), + WorkflowRunID: Int64(1), + } + + want := `{ + "action": "a", + "active": false, + "active_was": false, + "actor": "ac", + "blocked_user": "bu", + "business": "b", + "cancelled_at": ` + referenceTimeStr + `, + "completed_at": ` + referenceTimeStr + `, + "conclusion": "c", + "config": { + "url": "s" + }, + "config_was": { + "url": "s" + }, + "content_type": "ct", + "created_at": ` + referenceTimeStr + `, + "deploy_key_fingerprint": "dkf", + "_document_id": "did", + "emoji": "e", + "environment_name": "en", + "event": "e", + "events": [ + "s" + ], + "events_were": [ + "s" + ], + "explanation": "e", + "fingerprint": "f", + "head_branch": "hb", + "head_sha": "hsha", + "hook_id": 1, + "is_hosted_runner": false, + "job_name": "jn", + "limited_availability": false, + "message": "m", + "name": "n", + "old_user": "ou", + "openssh_public_key": "osshpk", + "org": "o", + "previous_visibility": "pv", + "read_only": "ro", + "repo": "r", + "repository": "repo", + "repository_public": false, + "runner_group_id": "rgid", + "runner_group_name": "rgn", + "runner_id": "rid", + "runner_labels": [ + "s" + ], + "runner_name": "rn", + "secrets_passed": [ + "s" + ], + "source_version": "sv", + "started_at": ` + referenceTimeStr + `, + "target_login": "tl", + "target_version": "tv", + "team": "t", + "@timestamp": ` + referenceTimeStr + `, + "transport_protocol_name": "tpn", + "transport_protocol": 1, + "trigger_id": 1, + "user": "u", + "visibility": "v", + "workflow_id": 1, + "workflow_run_id": 1 + }` + + testJSONMarshal(t, u, want) +}