github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/git/parse_nogogit_test.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 //go:build !gogit 7 8 package git 9 10 import ( 11 "testing" 12 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestParseTreeEntries(t *testing.T) { 17 testCases := []struct { 18 Input string 19 Expected []*TreeEntry 20 }{ 21 { 22 Input: `100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af 8218 README.md 23 100644 blob 037f27dc9d353ae4fd50f0474b2194c593914e35 4681 README_ZH.md 24 100644 blob 9846a94f7e8350a916632929d0fda38c90dd2ca8 429 SECURITY.md 25 040000 tree 84b90550547016f73c5dd3f50dea662389e67b6d - assets 26 `, 27 Expected: []*TreeEntry{ 28 { 29 ID: MustIDFromString("ea0d83c9081af9500ac9f804101b3fd0a5c293af"), 30 name: "README.md", 31 entryMode: EntryModeBlob, 32 size: 8218, 33 sized: true, 34 }, 35 { 36 ID: MustIDFromString("037f27dc9d353ae4fd50f0474b2194c593914e35"), 37 name: "README_ZH.md", 38 entryMode: EntryModeBlob, 39 size: 4681, 40 sized: true, 41 }, 42 { 43 ID: MustIDFromString("9846a94f7e8350a916632929d0fda38c90dd2ca8"), 44 name: "SECURITY.md", 45 entryMode: EntryModeBlob, 46 size: 429, 47 sized: true, 48 }, 49 { 50 ID: MustIDFromString("84b90550547016f73c5dd3f50dea662389e67b6d"), 51 name: "assets", 52 entryMode: EntryModeTree, 53 sized: true, 54 }, 55 }, 56 }, 57 } 58 for _, testCase := range testCases { 59 entries, err := ParseTreeEntries([]byte(testCase.Input)) 60 assert.NoError(t, err) 61 assert.Len(t, entries, len(testCase.Expected)) 62 for i, entry := range entries { 63 assert.EqualValues(t, testCase.Expected[i].ID, entry.ID) 64 assert.EqualValues(t, testCase.Expected[i].name, entry.name) 65 assert.EqualValues(t, testCase.Expected[i].entryMode, entry.entryMode) 66 assert.EqualValues(t, testCase.Expected[i].sized, entry.sized) 67 assert.EqualValues(t, testCase.Expected[i].size, entry.size) 68 } 69 } 70 }