-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish_test.go
More file actions
60 lines (49 loc) · 1.94 KB
/
Copy pathpublish_test.go
File metadata and controls
60 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestPublishPlanWritesCompactGitHubOutputs(t *testing.T) {
t.Parallel()
root := t.TempDir()
matrixPath := filepath.Join(root, "matrix.json")
summaryPath := filepath.Join(root, "summary.md")
outputPath := filepath.Join(root, "output.txt")
stepSummaryPath := filepath.Join(root, "step-summary.md")
summary := "## Summary\n"
err := publishPlan(outputSinks{
OutMatrix: matrixPath,
OutSummary: summaryPath,
GitHubOutput: outputPath,
GitHubStepSummary: stepSummaryPath,
}, matrixOutput{Include: []matrixEntry{{Package: "./pkg", RunRegex: "^(TestAlpha)(/.*)?$", TestCount: "10"}}}, summary, nil)
require.NoError(t, err)
matrixData, err := os.ReadFile(matrixPath)
require.NoError(t, err)
wantMatrix := `{"include":[{"package":"./pkg","run_regex":"^(TestAlpha)(/.*)?$","test_count":"10"}]}`
require.Equal(t, wantMatrix+"\n", string(matrixData))
outputData, err := os.ReadFile(outputPath)
require.NoError(t, err)
require.Equal(t, "matrix="+wantMatrix+"\n", string(outputData))
outputValue := strings.TrimSuffix(strings.TrimPrefix(string(outputData), "matrix="), "\n")
require.NotContains(t, outputValue, "\n")
localSummary, err := os.ReadFile(summaryPath)
require.NoError(t, err)
require.Equal(t, summary, string(localSummary))
stepSummary, err := os.ReadFile(stepSummaryPath)
require.NoError(t, err)
require.Equal(t, summary, string(stepSummary))
}
func TestPublishPlanWritesEmptyMatrixAndRejectsUnsafeOutput(t *testing.T) {
t.Parallel()
matrixData, err := marshalMatrix(matrixOutput{})
require.NoError(t, err)
require.Equal(t, `{"include":[]}`, string(matrixData))
err = ensureGitHubOutputFits("matrix", "first\nsecond", defaultGitHubOutputValueLimit)
require.ErrorContains(t, err, "single line")
err = ensureGitHubOutputFits("matrix", "too-long", 3)
require.ErrorContains(t, err, "above the 3 byte limit")
}