Skip to content

Commit

Permalink
fix: kaniko unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Dec 11, 2024
1 parent 440f744 commit cb93852
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions pkg/builder/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Kaniko struct {

var _ builder.Builder = &Kaniko{}

// sysDeps.K8sClient and sysDeps.MinioClient are required
// sysDeps.K8sClient is required and sysDeps.MinioClient is required if building from dir
// if reg is nil, it will use the default registry (ttl.sh)
func New(sysDeps *system.SystemDependencies, reg registry.Registry) (*Kaniko, error) {
if reg == nil {
Expand All @@ -56,10 +56,6 @@ func New(sysDeps *system.SystemDependencies, reg registry.Registry) (*Kaniko, er
return nil, ErrK8sClientRequired
}

if sysDeps.MinioClient == nil {
return nil, ErrMinioClientRequired
}

return &Kaniko{
SystemDependencies: sysDeps,
registry: reg,
Expand Down Expand Up @@ -257,6 +253,10 @@ func (k *Kaniko) prepareJob(ctx context.Context, b *builder.BuilderOptions) (*ba
// As kaniko also supports directly tar.gz archives, no need to extract it,
// we just need to set the context to tar://<path-to-archive>
func (k *Kaniko) mountDir(ctx context.Context, bCtx string, job *batchv1.Job) (*batchv1.Job, error) {
if k.MinioClient == nil {
return nil, ErrMinioClientRequired
}

// Create the tar.gz archive
archiveData, err := createTarGz(builder.GetDirFromBuildContext(bCtx))
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/builder/kaniko/kaniko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ func TestKanikoBuilder(t *testing.T) {
k8sCS := fake.NewSimpleClientset()
k8sClient, err := k8s.NewClientCustom(context.Background(), k8sCS, k8sCS.Discovery(), nil, k8sNamespace, logrus.New())
require.NoError(t, err)
kb := &Kaniko{
SystemDependencies: &system.SystemDependencies{
kb, err := New(
&system.SystemDependencies{
K8sClient: k8sClient,
},
}
nil,
)
require.NoError(t, err)
ctx := context.Background()

t.Run("BuildSuccess", func(t *testing.T) {
Expand Down

0 comments on commit cb93852

Please sign in to comment.