mirror of
https://github.com/ossf/scorecard.git
synced 2024-11-10 12:27:01 +03:00
2169bc44c7
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com> Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
// Copyright 2022 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 githubrepo
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/ossf/scorecard/v4/clients"
|
|
)
|
|
|
|
func TestSearchCommitsBuildQuery(t *testing.T) {
|
|
t.Parallel()
|
|
testcases := []struct {
|
|
searchReq clients.SearchCommitsOptions
|
|
expectedErrType error
|
|
name string
|
|
repourl *repoURL
|
|
expectedQuery string
|
|
hasError bool
|
|
}{
|
|
{
|
|
name: "Basic",
|
|
repourl: &repoURL{
|
|
owner: "testowner",
|
|
repo: "testrepo",
|
|
},
|
|
searchReq: clients.SearchCommitsOptions{
|
|
Author: "testAuthor",
|
|
},
|
|
expectedQuery: "repo:testowner/testrepo author:testAuthor",
|
|
},
|
|
{
|
|
name: "EmptyQuery",
|
|
repourl: &repoURL{
|
|
owner: "testowner",
|
|
repo: "testrepo",
|
|
},
|
|
searchReq: clients.SearchCommitsOptions{},
|
|
hasError: true,
|
|
expectedErrType: errEmptyQuery,
|
|
},
|
|
}
|
|
|
|
for _, testcase := range testcases {
|
|
testcase := testcase
|
|
t.Run(testcase.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
handler := searchCommitsHandler{
|
|
repourl: testcase.repourl,
|
|
}
|
|
|
|
query, err := handler.buildQuery(testcase.searchReq)
|
|
if !testcase.hasError && err != nil {
|
|
t.Fatalf("expected - no error, got: %v", err)
|
|
}
|
|
if testcase.hasError && !errors.Is(err, testcase.expectedErrType) {
|
|
t.Fatalf("expectedErrType - %v, got - %v",
|
|
testcase.expectedErrType, err)
|
|
} else if query != testcase.expectedQuery {
|
|
t.Fatalf("expectedQuery - %s, got - %s",
|
|
testcase.expectedQuery, query)
|
|
}
|
|
})
|
|
}
|
|
}
|