(t *testing.T)
| 28 | } |
| 29 | |
| 30 | func 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 | |
| 79 | func countLines(path string) (int, error) { |
| 80 | f, err := os.Open(path) |
nothing calls this directly
no test coverage detected