MCPcopy
hub / github.com/ossf/scorecard / TestClient_CreationAndCaching

Function TestClient_CreationAndCaching

clients/localdir/client_test.go:32–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestClient_CreationAndCaching(t *testing.T) {
33 t.Parallel()
34 tests := []struct {
35 name string
36 inputFolder string
37 err error
38 outputFiles []string
39 }{
40 {
41 name: "invalid fullpath",
42 outputFiles: []string{},
43 inputFolder: "invalid/fullpath",
44 err: os.ErrNotExist,
45 },
46 {
47 name: "invalid relative path",
48 outputFiles: []string{},
49 inputFolder: "invalid/relative/path",
50 err: os.ErrNotExist,
51 },
52 {
53 name: "repo 0",
54 outputFiles: []string{
55 "file0", "dir1/file1", "dir1/dir2/file2",
56 },
57 inputFolder: "testdata/repo0",
58 err: nil,
59 },
60 }
61 for _, tt := range tests {
62 t.Run(tt.name, func(t *testing.T) {
63 t.Parallel()
64
65 ctx := t.Context()
66 logger := log.NewLogger(log.DebugLevel)
67
68 // Create repo.
69 repo, err := MakeLocalDirRepo(tt.inputFolder)
70 if !errors.Is(err, tt.err) {
71 t.Errorf("MakeLocalDirRepo: %v, expected %v", err, tt.err)
72 }
73
74 if err != nil {
75 return
76 }
77
78 client := CreateLocalDirClient(ctx, logger)
79 if err := client.InitRepo(repo, clients.HeadSHA, 30); err != nil {
80 t.Errorf("InitRepo: %v", err)
81 }
82
83 // List files.
84 files, err := client.ListFiles(func(string) (bool, error) { return true, nil })
85 if !errors.Is(err, tt.err) {
86 t.Errorf("CreateLocalDirClient: %v, expected %v", err, tt.err)
87 }
88
89 if !cmp.Equal(tt.outputFiles, files, cmpopts.SortSlices(func(x, y string) bool { return x < y })) {

Callers

nothing calls this directly

Calls 6

NewLoggerFunction · 0.92
MakeLocalDirRepoFunction · 0.85
CreateLocalDirClientFunction · 0.85
RunMethod · 0.65
InitRepoMethod · 0.65
ListFilesMethod · 0.65

Tested by

no test coverage detected