MCPcopy Create free account
hub / github.com/conforma/cli / Test_ValidatePipeline

Function Test_ValidatePipeline

internal/input/validate_test.go:77–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func Test_ValidatePipeline(t *testing.T) {
78 emptyDir := "/empty"
79 nonEmptyDir := "/nonEmpty"
80 validFile := filepath.Join(nonEmptyDir, "file.json")
81 badPath := "bad"
82
83 tests := []struct {
84 name string
85 fpath string
86 err error
87 output *output.Output
88 defFunc func(ctx context.Context, fpath []string, policy policy.Policy) (*input.Input, error)
89 }{
90 {
91 name: "validation succeeds",
92 fpath: validFile,
93 err: nil,
94 output: &output.Output{},
95 defFunc: mockNewPipelineDefinitionFile,
96 },
97 {
98 name: "validation fails on empty directory",
99 fpath: emptyDir,
100 err: fmt.Errorf("the directory %v contained no files", emptyDir),
101 output: nil,
102 defFunc: mockNewPipelineDefinitionFile,
103 },
104 {
105 name: "validation fails on bad path",
106 fpath: badPath,
107 err: fmt.Errorf("unable to parse the provided input file: %v", badPath),
108 output: nil,
109 defFunc: mockNewPipelineDefinitionFile,
110 },
111 {
112 name: "valid file, but evaluator fails",
113 fpath: validFile,
114 err: fmt.Errorf("evaluating policy: %w", errors.New("Evaluator error")),
115 output: nil,
116 defFunc: badMockNewPipelineDefinitionFile,
117 },
118 {
119 name: "validation succeeds with json input",
120 fpath: "{\"json\": 1}",
121 err: nil,
122 output: &output.Output{},
123 defFunc: mockNewPipelineDefinitionFile,
124 },
125 {
126 name: "validation succeeds with yaml input",
127 fpath: "kind: task",
128 err: nil,
129 output: &output.Output{},
130 defFunc: mockNewPipelineDefinitionFile,
131 },
132 {
133 name: "validation fails with only an array of strings as yaml",
134 fpath: "- test1\n- test2",

Callers

nothing calls this directly

Calls 4

WithFSFunction · 0.92
ValidateInputFunction · 0.85
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected