From 068f30f1615ea92facd6dd729a173ecf5d3ee3dd Mon Sep 17 00:00:00 2001 From: Tosone Date: Sun, 14 Jan 2024 15:21:43 +0800 Subject: [PATCH] :white_check_mark: Add unit test for signing init (#281) --- cmd/builder/builder.go | 2 +- pkg/dal/dao/builder_test.go | 32 ++++++++++++++++++++++++ pkg/dal/dao/cache_test.go | 32 ++++++++++++++++++++++++ pkg/dal/dao/code_repository_test.go | 32 ++++++++++++++++++++++++ pkg/dal/dao/daemon_test.go | 17 +++++++++++++ pkg/dal/dao/locker_test.go | 32 ++++++++++++++++++++++++ pkg/inits/signing_test.go | 38 +++++++++++++++++++++++++++++ pkg/signing/signing.go | 6 ++--- 8 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 pkg/dal/dao/builder_test.go create mode 100644 pkg/dal/dao/cache_test.go create mode 100644 pkg/dal/dao/code_repository_test.go create mode 100644 pkg/dal/dao/locker_test.go create mode 100644 pkg/inits/signing_test.go diff --git a/cmd/builder/builder.go b/cmd/builder/builder.go index eed6677e..3934f797 100644 --- a/cmd/builder/builder.go +++ b/cmd/builder/builder.go @@ -298,7 +298,7 @@ func (b Builder) sign(imageName string) error { s := signing.NewSigning(signing.Options{ Type: enums.SigningTypeCosign, Http: strings.HasPrefix(b.Endpoint, "http://"), - Multiarch: len(b.BuildkitPlatforms) > 1, + MultiArch: len(b.BuildkitPlatforms) > 1, }) return s.Sign(context.Background(), b.Authorization, b.SigningPrivateKey, imageName) } diff --git a/pkg/dal/dao/builder_test.go b/pkg/dal/dao/builder_test.go new file mode 100644 index 00000000..8d5cd9df --- /dev/null +++ b/pkg/dal/dao/builder_test.go @@ -0,0 +1,32 @@ +// Copyright 2024 sigma +// +// 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 dao_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/go-sigma/sigma/pkg/dal/dao" + "github.com/go-sigma/sigma/pkg/dal/query" +) + +func TestBuilderServiceFactory(t *testing.T) { + f := dao.NewBuilderServiceFactory() + artifactService := f.New() + assert.NotNil(t, artifactService) + artifactService = f.New(query.Q) + assert.NotNil(t, artifactService) +} diff --git a/pkg/dal/dao/cache_test.go b/pkg/dal/dao/cache_test.go new file mode 100644 index 00000000..7b0b081f --- /dev/null +++ b/pkg/dal/dao/cache_test.go @@ -0,0 +1,32 @@ +// Copyright 2024 sigma +// +// 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 dao_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/go-sigma/sigma/pkg/dal/dao" + "github.com/go-sigma/sigma/pkg/dal/query" +) + +func TestCacheServiceFactory(t *testing.T) { + f := dao.NewCacheServiceFactory() + artifactService := f.New() + assert.NotNil(t, artifactService) + artifactService = f.New(query.Q) + assert.NotNil(t, artifactService) +} diff --git a/pkg/dal/dao/code_repository_test.go b/pkg/dal/dao/code_repository_test.go new file mode 100644 index 00000000..ab1acba3 --- /dev/null +++ b/pkg/dal/dao/code_repository_test.go @@ -0,0 +1,32 @@ +// Copyright 2024 sigma +// +// 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 dao_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/go-sigma/sigma/pkg/dal/dao" + "github.com/go-sigma/sigma/pkg/dal/query" +) + +func TestCodeRepositoryServiceFactory(t *testing.T) { + f := dao.NewCodeRepositoryServiceFactory() + artifactService := f.New() + assert.NotNil(t, artifactService) + artifactService = f.New(query.Q) + assert.NotNil(t, artifactService) +} diff --git a/pkg/dal/dao/daemon_test.go b/pkg/dal/dao/daemon_test.go index 9e1492ed..d97befe8 100644 --- a/pkg/dal/dao/daemon_test.go +++ b/pkg/dal/dao/daemon_test.go @@ -13,3 +13,20 @@ // limitations under the License. package dao_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/go-sigma/sigma/pkg/dal/dao" + "github.com/go-sigma/sigma/pkg/dal/query" +) + +func TestDaemonServiceFactory(t *testing.T) { + f := dao.NewDaemonServiceFactory() + artifactService := f.New() + assert.NotNil(t, artifactService) + artifactService = f.New(query.Q) + assert.NotNil(t, artifactService) +} diff --git a/pkg/dal/dao/locker_test.go b/pkg/dal/dao/locker_test.go new file mode 100644 index 00000000..aa89f240 --- /dev/null +++ b/pkg/dal/dao/locker_test.go @@ -0,0 +1,32 @@ +// Copyright 2024 sigma +// +// 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 dao_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/go-sigma/sigma/pkg/dal/dao" + "github.com/go-sigma/sigma/pkg/dal/query" +) + +func TestLockerServiceFactory(t *testing.T) { + f := dao.NewLockerServiceFactory() + artifactService := f.New() + assert.NotNil(t, artifactService) + artifactService = f.New(query.Q) + assert.NotNil(t, artifactService) +} diff --git a/pkg/inits/signing_test.go b/pkg/inits/signing_test.go new file mode 100644 index 00000000..35f119c6 --- /dev/null +++ b/pkg/inits/signing_test.go @@ -0,0 +1,38 @@ +// Copyright 2023 sigma +// +// 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 inits + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/go-sigma/sigma/pkg/configs" + "github.com/go-sigma/sigma/pkg/dal" + "github.com/go-sigma/sigma/pkg/tests" +) + +func TestSigning(t *testing.T) { + assert.NoError(t, tests.Initialize(t)) + assert.NoError(t, tests.DB.Init()) + defer func() { + conn, err := dal.DB.DB() + assert.NoError(t, err) + assert.NoError(t, conn.Close()) + assert.NoError(t, tests.DB.DeInit()) + }() + + assert.NoError(t, signing(configs.Configuration{})) +} diff --git a/pkg/signing/signing.go b/pkg/signing/signing.go index f92f8efb..a4448625 100644 --- a/pkg/signing/signing.go +++ b/pkg/signing/signing.go @@ -25,15 +25,15 @@ type Options struct { Type enums.SigningType Http bool - Multiarch bool + MultiArch bool } // NewSigning ... func NewSigning(opt Options) definition.Signing { switch opt.Type { case enums.SigningTypeCosign: - return sign.New(opt.Http, opt.Multiarch) + return sign.New(opt.Http, opt.MultiArch) default: - return sign.New(opt.Http, opt.Multiarch) + return sign.New(opt.Http, opt.MultiArch) } }