mirror of
https://github.com/ossf/scorecard.git
synced 2024-10-05 13:17:08 +03:00
d8ba4268bf
Some checks failed
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
gitlab-tests / gitlab-integration-trusted (push) Has been cancelled
golangci-lint / check-linter (push) Has been cancelled
build / unit-test (push) Has been cancelled
build / generate-mocks (push) Has been cancelled
build / generate-docs (push) Has been cancelled
build / build-proto (push) Has been cancelled
build / validate-docs (push) Has been cancelled
build / add-projects (push) Has been cancelled
build / validate-projects (push) Has been cancelled
build / license boilerplate check (push) Has been cancelled
Scorecard analysis workflow / Scorecard analysis (push) Has been cancelled
build / ${{ matrix.target }} (build-add-script) (push) Has been cancelled
build / ${{ matrix.target }} (build-bq-transfer) (push) Has been cancelled
build / ${{ matrix.target }} (build-cii-worker) (push) Has been cancelled
build / ${{ matrix.target }} (build-controller) (push) Has been cancelled
build / ${{ matrix.target }} (build-github-server) (push) Has been cancelled
build / ${{ matrix.target }} (build-scorecard) (push) Has been cancelled
build / ${{ matrix.target }} (build-shuffler) (push) Has been cancelled
build / ${{ matrix.target }} (build-validate-script) (push) Has been cancelled
build / ${{ matrix.target }} (build-webhook) (push) Has been cancelled
build / ${{ matrix.target }} (build-worker) (push) Has been cancelled
130 lines
3.2 KiB
Go
130 lines
3.2 KiB
Go
// Copyright 2023 OpenSSF Scorecard Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package finding
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
)
|
|
|
|
func Test_probeFromBytes(t *testing.T) {
|
|
t.Parallel()
|
|
//nolint:govet
|
|
tests := []struct {
|
|
name string
|
|
id string
|
|
path string
|
|
err error
|
|
probe *probe
|
|
}{
|
|
{
|
|
name: "all fields set",
|
|
id: "all-fields",
|
|
path: "testdata/all-fields.yml",
|
|
probe: &probe{
|
|
ID: "all-fields",
|
|
Short: "short description",
|
|
Implementation: "impl1 impl2\n",
|
|
Motivation: "mot1 mot2\n",
|
|
Remediation: &Remediation{
|
|
Text: "step1\nstep2 https://www.google.com/something",
|
|
Markdown: "step1\nstep2 [google.com](https://www.google.com/something)",
|
|
Effort: RemediationEffortLow,
|
|
},
|
|
RemediateOnOutcome: OutcomeFalse,
|
|
},
|
|
},
|
|
{
|
|
name: "mismatch probe ID",
|
|
id: "mismatch-id",
|
|
path: "testdata/all-fields.yml",
|
|
probe: &probe{
|
|
ID: "all-fields",
|
|
Short: "short description",
|
|
Implementation: "impl1 impl2\n",
|
|
Motivation: "mot1 mot2\n",
|
|
Remediation: &Remediation{
|
|
Text: "step1\nstep2 https://www.google.com/something",
|
|
Markdown: "step1\nstep2 [google.com](https://www.google.com/something)",
|
|
Effort: RemediationEffortLow,
|
|
},
|
|
},
|
|
err: errInvalid,
|
|
},
|
|
{
|
|
name: "missing id",
|
|
id: "missing-id",
|
|
path: "testdata/missing-id.yml",
|
|
err: errInvalid,
|
|
},
|
|
{
|
|
name: "invalid effort",
|
|
id: "invalid-effort",
|
|
path: "testdata/invalid-effort.yml",
|
|
err: errInvalid,
|
|
},
|
|
{
|
|
name: "invalid language",
|
|
id: "invalid-language",
|
|
path: "testdata/invalid-language.yml",
|
|
err: errInvalid,
|
|
},
|
|
{
|
|
name: "invalid client",
|
|
id: "invalid-client",
|
|
path: "testdata/invalid-client.yml",
|
|
err: errInvalid,
|
|
},
|
|
{
|
|
name: "invalid lifecycle is an error",
|
|
id: "invalid-lifecycle",
|
|
path: "testdata/invalid-lifecycle.yml",
|
|
err: errInvalid,
|
|
},
|
|
{
|
|
name: "missing lifecycle is an error",
|
|
id: "missing-lifecycle",
|
|
path: "testdata/missing-lifecycle.yml",
|
|
err: errInvalid,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt // Re-initializing variable so it is not changed while executing the closure below
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
content, err := os.ReadFile(tt.path)
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
r, err := probeFromBytes(content, tt.id)
|
|
if err != nil || tt.err != nil {
|
|
if !errCmp(err, tt.err) {
|
|
t.Fatalf("unexpected error: %v", cmp.Diff(err, tt.err, cmpopts.EquateErrors()))
|
|
}
|
|
return
|
|
}
|
|
|
|
if diff := cmp.Diff(*tt.probe, *r); diff != "" {
|
|
t.Errorf("mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|