Debian Codegraph @

internal/mock/ocilayout/ocilayout_test.go

raw
1 // Copyright The Notary Project Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package ocilayout
15
16 import (
17 "os"
18 "runtime"
19 "testing"
20 )
21
22 func TestCopy(t *testing.T) {
23 t.Run("empty oci layout", func(t *testing.T) {
24 err := Copy("", "", "v2")
25 if err == nil {
26 t.Errorf("expected error, got nil")
27 }
28 })
29
30 t.Run("invalid target path permission", func(t *testing.T) {
31 if runtime.GOOS == "windows" {
32 t.Skip("skipping test on Windows")
33 }
34 tempDir := t.TempDir()
35 // change the permission of the tempDir to make it invalid
36 if err := os.Chmod(tempDir, 0); err != nil {
37 t.Fatalf("failed to change the permission of the tempDir: %v", err)
38 }
39 err := Copy("../../testdata/oci-layout", tempDir, "v2")
40 if err == nil {
41 t.Errorf("expected error, got nil")
42 }
43
44 if err := os.Chmod(tempDir, 0755); err != nil {
45 t.Fatalf("failed to change the permission of the tempDir: %v", err)
46 }
47 })
48
49 t.Run("copy failed", func(t *testing.T) {
50 tempDir := t.TempDir()
51 err := Copy("../../testdata/oci-layout", tempDir, "v3")
52 if err == nil {
53 t.Errorf("expected error, got nil")
54 }
55 })
56
57 t.Run("copy success", func(t *testing.T) {
58 tempDir := t.TempDir()
59 err := Copy("../../testdata/oci-layout", tempDir, "v2")
60 if err != nil {
61 t.Errorf("expected nil, got %v", err)
62 }
63 })
64 }