From 413f16a06bb69dd34e660e2a636006e47f658ddc Mon Sep 17 00:00:00 2001 From: Zhao Chen Date: Fri, 24 Apr 2026 15:05:42 +0800 Subject: [PATCH] test(backend): cover upload missing file stat error Signed-off-by: Zhao Chen --- pkg/backend/upload_test.go | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 pkg/backend/upload_test.go diff --git a/pkg/backend/upload_test.go b/pkg/backend/upload_test.go new file mode 100644 index 0000000..dcb159a --- /dev/null +++ b/pkg/backend/upload_test.go @@ -0,0 +1,43 @@ +/* + * Copyright 2025 The CNAI 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 backend + +import ( + "context" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/modelpack/modctl/pkg/config" + mockstore "github.com/modelpack/modctl/test/mocks/storage" +) + +func TestUploadMissingFileReturnsProcessorStatError(t *testing.T) { + b := &backend{store: &mockstore.Storage{}} + missingFile := filepath.Join(t.TempDir(), "missing.unknown") + + err := b.Upload(context.Background(), missingFile, &config.Upload{ + Repo: "example.com/acme/model", + }) + + if assert.Error(t, err) { + assert.ErrorContains(t, err, "failed to get processor") + assert.ErrorContains(t, err, "failed to stat file") + assert.ErrorContains(t, err, missingFile) + } +}