MCPcopy Index your code
hub / github.com/cli/cli / TestCommitExportData

Function TestCommitExportData

pkg/search/result_test.go:61–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestCommitExportData(t *testing.T) {
62 var authoredAt = time.Date(2021, 2, 27, 11, 30, 0, 0, time.UTC)
63 var committedAt = time.Date(2021, 2, 28, 12, 30, 0, 0, time.UTC)
64 tests := []struct {
65 name string
66 fields []string
67 commit Commit
68 output string
69 }{
70 {
71 name: "exports requested fields",
72 fields: []string{"author", "commit", "committer", "sha"},
73 commit: Commit{
74 Author: User{Login: "foo"},
75 Committer: User{Login: "bar", ID: "123"},
76 Info: CommitInfo{
77 Author: CommitUser{Date: authoredAt, Name: "Foo"},
78 Committer: CommitUser{Date: committedAt, Name: "Bar"},
79 Message: "test message",
80 },
81 Sha: "8dd03144ffdc6c0d",
82 },
83 output: `{"author":{"id":"","is_bot":true,"login":"app/foo","type":"","url":""},"commit":{"author":{"date":"2021-02-27T11:30:00Z","email":"","name":"Foo"},"comment_count":0,"committer":{"date":"2021-02-28T12:30:00Z","email":"","name":"Bar"},"message":"test message","tree":{"sha":""}},"committer":{"id":"123","is_bot":false,"login":"bar","type":"","url":""},"sha":"8dd03144ffdc6c0d"}`,
84 },
85 }
86 for _, tt := range tests {
87 t.Run(tt.name, func(t *testing.T) {
88 exported := tt.commit.ExportData(tt.fields)
89 buf := bytes.Buffer{}
90 enc := json.NewEncoder(&buf)
91 require.NoError(t, enc.Encode(exported))
92 assert.Equal(t, tt.output, strings.TrimSpace(buf.String()))
93 })
94 }
95}
96
97func TestRepositoryExportData(t *testing.T) {
98 var createdAt = time.Date(2021, 2, 28, 12, 30, 0, 0, time.UTC)

Callers

nothing calls this directly

Calls 4

EqualMethod · 0.80
RunMethod · 0.65
ExportDataMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected