Skip to content

Commit

Permalink
✅ Add unit test for signing init (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone authored Jan 14, 2024
1 parent 5c352c4 commit 068f30f
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/dal/dao/builder_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
32 changes: 32 additions & 0 deletions pkg/dal/dao/cache_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
32 changes: 32 additions & 0 deletions pkg/dal/dao/code_repository_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 17 additions & 0 deletions pkg/dal/dao/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
32 changes: 32 additions & 0 deletions pkg/dal/dao/locker_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
38 changes: 38 additions & 0 deletions pkg/inits/signing_test.go
Original file line number Diff line number Diff line change
@@ -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{}))
}
6 changes: 3 additions & 3 deletions pkg/signing/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 068f30f

Please sign in to comment.