MCPcopy
hub / github.com/cli/cli / TestCreateJSONLinesFilePath

Function TestCreateJSONLinesFilePath

pkg/cmd/attestation/download/metadata_test.go:30–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func TestCreateJSONLinesFilePath(t *testing.T) {
31 tempDir := t.TempDir()
32 artifact, err := artifact.NewDigestedArtifact(oci.MockClient{}, "../test/data/sigstore-js-2.1.0.tgz", "sha512")
33 require.NoError(t, err)
34
35 var expectedFileName string
36 if runtime.GOOS == "windows" {
37 expectedFileName = fmt.Sprintf("%s-%s.jsonl", artifact.Algorithm(), artifact.Digest())
38 } else {
39 expectedFileName = fmt.Sprintf("%s.jsonl", artifact.DigestWithAlg())
40 }
41
42 testCases := []struct {
43 name string
44 outputPath string
45 expected string
46 }{
47 {
48 name: "with output path",
49 outputPath: tempDir,
50 expected: path.Join(tempDir, expectedFileName),
51 },
52 {
53 name: "with nested output path",
54 outputPath: path.Join(tempDir, "subdir"),
55 expected: path.Join(tempDir, "subdir", expectedFileName),
56 },
57 {
58 name: "with output path with beginning slash",
59 outputPath: path.Join("/", tempDir, "subdir"),
60 expected: path.Join("/", tempDir, "subdir", expectedFileName),
61 },
62 {
63 name: "without output path",
64 outputPath: "",
65 expected: expectedFileName,
66 },
67 }
68
69 for _, tc := range testCases {
70 store := LiveStore{
71 tc.outputPath,
72 }
73
74 actualPath := store.createJSONLinesFilePath(artifact.DigestWithAlg())
75 require.Equal(t, tc.expected, actualPath)
76 }
77}
78
79func countLines(path string) (int, error) {
80 f, err := os.Open(path)

Callers

nothing calls this directly

Calls 6

AlgorithmMethod · 0.95
DigestMethod · 0.95
DigestWithAlgMethod · 0.95
JoinMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected