Skip to content

Commit

Permalink
more linter errors from local run
Browse files Browse the repository at this point in the history
  • Loading branch information
renzodavid9 committed May 21, 2024
1 parent e4e63b3 commit 9339b2c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 26 deletions.
3 changes: 2 additions & 1 deletion pkg/chains/formats/slsa/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func subjectsFromPipelineRun(ctx context.Context, obj objects.TektonObject, slsa

pSpec := pro.Status.PipelineSpec
if pSpec != nil {
pipelineTasks := append(pSpec.Tasks, pSpec.Finally...)
pipelineTasks := pSpec.Tasks
pipelineTasks = append(pipelineTasks, pSpec.Finally...)
for _, t := range pipelineTasks {
tr := pro.GetTaskRunFromTask(t.Name)
// Ignore Tasks that did not execute during the PipelineRun.
Expand Down
9 changes: 4 additions & 5 deletions pkg/chains/formats/slsa/extract/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func TestSubjectDigestsAndRetrieveAllArtifactURIs(t *testing.T) {
t.Errorf("Wrong URIs extracted, diff=%s", diff)
}
}

})
}
}
Expand Down Expand Up @@ -209,7 +208,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) {
{
name: "deep inspection enabled: pipelinerun and taskrun have duplicated results",
pro: createProWithTaskRunResults(
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1),
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}),
[]artifact{
{uri: artifactURL1, digest: "sha256:" + artifactDigest1},
}),
Expand All @@ -229,7 +228,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) {
{
name: "deep inspection enabled: pipelinerun and taskrun have different results",
pro: createProWithTaskRunResults(
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1),
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}),
[]artifact{
{uri: artifactURL2, digest: "sha256:" + artifactDigest2},
}),
Expand Down Expand Up @@ -441,7 +440,7 @@ func TestSubjectsFromBuildArtifact(t *testing.T) {
}
}

func createTaskRunObjectWithResults(results map[string]string) objects.TektonObject {
func createTaskRunObjectWithResults(results map[string]string) *objects.TaskRunObjectV1 {
trResults := []v1.TaskRunResult{}
prefix := 0
for url, digest := range results {
Expand All @@ -463,7 +462,7 @@ func createTaskRunObjectWithResults(results map[string]string) objects.TektonObj
)
}

func createProWithPipelineResults(results map[string]string) objects.TektonObject {
func createProWithPipelineResults(results map[string]string) *objects.PipelineRunObjectV1 {
prResults := []v1.PipelineRunResult{}
prefix := 0
for url, digest := range results {
Expand Down
8 changes: 4 additions & 4 deletions pkg/chains/formats/slsa/extract/v1beta1/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) {
{
name: "deep inspection enabled: pipelinerun and taskrun have duplicated results",
pro: createProWithTaskRunResults(
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1Beta1),
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}),
[]artifact{
{uri: artifactURL1, digest: "sha256:" + artifactDigest1},
}),
Expand All @@ -229,7 +229,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) {
{
name: "deep inspection enabled: pipelinerun and taskrun have different results",
pro: createProWithTaskRunResults(
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1Beta1),
createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}),
[]artifact{
{uri: artifactURL2, digest: "sha256:" + artifactDigest2},
}),
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) {
}
}

func createTaskRunObjectV1Beta1WithResults(results map[string]string) objects.TektonObject {
func createTaskRunObjectV1Beta1WithResults(results map[string]string) *objects.TaskRunObjectV1Beta1 {
trResults := []v1beta1.TaskRunResult{}
prefix := 0
for url, digest := range results {
Expand All @@ -294,7 +294,7 @@ func createTaskRunObjectV1Beta1WithResults(results map[string]string) objects.Te
)
}

func createProWithPipelineResults(results map[string]string) objects.TektonObject {
func createProWithPipelineResults(results map[string]string) *objects.PipelineRunObjectV1Beta1 {
prResults := []v1beta1.PipelineRunResult{}
prefix := 0
for url, digest := range results {
Expand Down
6 changes: 4 additions & 2 deletions pkg/chains/formats/slsa/internal/material/v1beta1/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func PipelineMaterials(ctx context.Context, pro *objects.PipelineRunObjectV1Beta
}
pSpec := pro.Status.PipelineSpec
if pSpec != nil {
pipelineTasks := append(pSpec.Tasks, pSpec.Finally...)
pipelineTasks := pSpec.Tasks
pipelineTasks = append(pipelineTasks, pSpec.Finally...)
for _, t := range pipelineTasks {
tr := pro.GetTaskRunFromTask(t.Name)
// Ignore Tasks that did not execute during the PipelineRun.
Expand Down Expand Up @@ -269,7 +270,8 @@ func FromPipelineParamsAndResults(ctx context.Context, pro *objects.PipelineRunO
// search type hinting param/results from each individual taskruns
if slsaconfig.DeepInspectionEnabled {
logger := logging.FromContext(ctx)
pipelineTasks := append(pSpec.Tasks, pSpec.Finally...)
pipelineTasks := pSpec.Tasks
pipelineTasks = append(pipelineTasks, pSpec.Finally...)
for _, t := range pipelineTasks {
tr := pro.GetTaskRunFromTask(t.Name)
// Ignore Tasks that did not execute during the PipelineRun.
Expand Down
7 changes: 2 additions & 5 deletions pkg/chains/formats/slsa/v2alpha3/slsav2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@ func TestCreatePayloadError(t *testing.T) {
}
if err == nil {
t.Errorf("Expected error")
} else {
if err.Error() != "intoto does not support type: not a task ref" {
t.Errorf("wrong error returned: '%s'", err.Error())
}
} else if err.Error() != "intoto does not support type: not a task ref" {
t.Errorf("wrong error returned: '%s'", err.Error())
}
})

}

func TestCorrectPayloadType(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/chains/formats/slsa/v2alpha4/slsav2.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Slsa struct {
}

// NewFormatter returns a new v2alpha4 payloader.
func NewFormatter(cfg config.Config) (formats.Payloader, error) {
func NewFormatter(cfg config.Config) (formats.Payloader, error) { //nolint:ireturn
return &Slsa{
slsaConfig: &slsaconfig.SlsaConfig{
BuilderID: cfg.Builder.ID,
Expand Down
10 changes: 4 additions & 6 deletions pkg/chains/storage/grafeas/grafeas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func TestGrafeasBackend_StoreAndRetrieve(t *testing.T) {
wantErr: false,
},
{
name: "intoto for the ci pipeline, no error, 2 occurences should be created for the pipelinerun for the 2 artifact generated.",
name: "intoto for the ci pipeline, no error, 2 occurrences should be created for the pipelinerun for the 2 artifact generated.",
args: args{
runObject: &objects.PipelineRunObjectV1Beta1{
PipelineRun: ciPipeline,
Expand Down Expand Up @@ -337,10 +337,9 @@ func TestGrafeasBackend_StoreAndRetrieve(t *testing.T) {
}
defer conn.Close()

// collect all the occurences expected to be created in the server
// collect all the occurrences expected to be created in the server
allOccurrencesInServer := []*pb.Occurrence{}
for _, test := range tests {

// run the test
t.Run(test.name, func(t *testing.T) {
ctx := logging.WithLogger(ctx, logtesting.TestLogger(t))
Expand Down Expand Up @@ -573,7 +572,7 @@ func getRawPayload(t *testing.T, in interface{}) []byte {

// set up the connection between grafeas server and client
// and return the client object to the caller
func setupConnection() (*grpc.ClientConn, pb.GrafeasClient, error) {
func setupConnection() (*grpc.ClientConn, pb.GrafeasClient, error) { //nolint:ireturn
serv := grpc.NewServer()
pb.RegisterGrafeasServer(serv, &mockGrafeasServer{})

Expand Down Expand Up @@ -627,7 +626,7 @@ func (s *mockGrafeasServer) CreateOccurrence(ctx context.Context, req *pb.Create
occ := req.GetOccurrence()
noteName := req.GetOccurrence().NoteName
resourceUri := req.GetOccurrence().ResourceUri
occ.Name = resourceUri // mock how the occurrence ID (name) is outputed.
occ.Name = resourceUri // mock how the occurrence ID (name) is outputted.

if note, ok := s.entries[noteName]; ok {
if _, ok := note.occurrences[resourceUri]; ok {
Expand Down Expand Up @@ -714,7 +713,6 @@ func (s *mockGrafeasServer) getOccurrencesByFilter(filter string, occurrences []
// mock how uri filter works
uris := parseURIFilterString(filter)

// result result
result := []*pb.Occurrence{}

for _, occ := range occurrences {
Expand Down
4 changes: 2 additions & 2 deletions pkg/chains/storage/tekton/tekton.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (b *Backend) retrieveAnnotationValue(ctx context.Context, obj objects.Tekto
var annotationValue string
annotations, err := obj.GetLatestAnnotations(ctx, b.pipelineclientset)
if err != nil {
return "", fmt.Errorf("error retrieving the annotation value for the key %q: %s", annotationKey, err)
return "", fmt.Errorf("error retrieving the annotation value for the key %q: %w", annotationKey, err)
}
val, ok := annotations[annotationKey]

Expand All @@ -99,7 +99,7 @@ func (b *Backend) retrieveAnnotationValue(ctx context.Context, obj objects.Tekto
if decode {
decodedAnnotation, err := base64.StdEncoding.DecodeString(val)
if err != nil {
return "", fmt.Errorf("error decoding the annotation value for the key %q: %s", annotationKey, err)
return "", fmt.Errorf("error decoding the annotation value for the key %q: %w", annotationKey, err)
}
annotationValue = string(decodedAnnotation)
} else {
Expand Down

0 comments on commit 9339b2c

Please sign in to comment.