diff --git a/checker/detail_logger_impl_test.go b/checker/detail_logger_impl_test.go new file mode 100644 index 000000000000..c1cebcb8a61d --- /dev/null +++ b/checker/detail_logger_impl_test.go @@ -0,0 +1,79 @@ +// 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 checker + +import ( + "testing" +) + +func Test_logger_Info(t *testing.T) { + l := &logger{ + logs: []CheckDetail{}, + } + l.Info(&LogMessage{Text: "test"}) + if len(l.logs) != 1 && l.logs[0].Type != DetailInfo { + t.Errorf("expected 1 log, got %d", len(l.logs)) + } +} + +func Test_logger_Warn(t *testing.T) { + l := &logger{ + logs: []CheckDetail{}, + } + l.Warn(&LogMessage{Text: "test"}) + if len(l.logs) != 1 && l.logs[0].Type != DetailWarn { + t.Errorf("expected 1 log, got %d", len(l.logs)) + } +} + +func Test_logger_Flush(t *testing.T) { + l := &logger{ + logs: []CheckDetail{}, + } + l.Warn(&LogMessage{Text: "test"}) + ret := l.Flush() + if len(ret) != 1 { + t.Errorf("expected 1 log, got %d", len(ret)) + } + if len(l.logs) != 0 { + t.Errorf("expected 0 log, got %d", len(l.logs)) + } +} + +func Test_logger_Logs(t *testing.T) { + l := &logger{ + logs: []CheckDetail{}, + } + l.Warn(&LogMessage{Text: "test"}) + if len(l.Logs()) != 1 { + t.Errorf("expected 1 log, got %d", len(l.logs)) + } +} + +func Test_logger_Debug(t *testing.T) { + l := &logger{ + logs: []CheckDetail{}, + } + l.Debug(&LogMessage{Text: "test"}) + if len(l.logs) != 1 && l.logs[0].Type != DetailDebug { + t.Errorf("expected 1 log, got %d", len(l.logs)) + } +} + +func TestNewLogger(t *testing.T) { + l := NewLogger() + if l == nil { + t.Errorf("expected non-nil logger, got nil") + } +} diff --git a/checker/raw_result.go b/checker/raw_result.go index 6aa2e4082e55..318a039a997c 100644 --- a/checker/raw_result.go +++ b/checker/raw_result.go @@ -81,7 +81,7 @@ type Package struct { Runs []Run } -// DependencyUseType reprensets a type of dependency use. +// DependencyUseType represents a type of dependency use. type DependencyUseType string const ( @@ -325,7 +325,7 @@ type DangerousWorkflow struct { File File } -// WorkflowJob reprresents a workflow job. +// WorkflowJob represents a workflow job. type WorkflowJob struct { Name *string ID *string @@ -350,7 +350,7 @@ const ( type PermissionLevel string const ( - // PermissionLevelUndeclared is an undecleared permission. + // PermissionLevelUndeclared is an undeclared permission. PermissionLevelUndeclared PermissionLevel = "undeclared" // PermissionLevelWrite is a permission set to `write` for a permission we consider potentially dangerous. PermissionLevelWrite PermissionLevel = "write"