Debian Codegraph @

config/base_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 config
15
16 import (
17 "fmt"
18 "os"
19 "path/filepath"
20 "runtime"
21 "testing"
22
23 "github.com/notaryproject/notation-go/dir"
24 )
25
26 func TestLoadNonExistentFile(t *testing.T) {
27 dir.UserConfigDir = "testdata/valid"
28
29 var config string
30 err := load("non-existent", &config)
31 if err == nil {
32 t.Fatalf("load() expected error but not found")
33 }
34 }
35
36 func TestLoadSymlink(t *testing.T) {
37 if runtime.GOOS == "windows" {
38 t.Skip("skipping test on Windows")
39 }
40 root := t.TempDir()
41 dir.UserConfigDir = root
42 fileName := "symlink"
43 os.Symlink("testdata/valid/config.json", filepath.Join(root, fileName))
44
45 expectedError := fmt.Sprintf("\"%s/%s\" is not a regular file (symlinks are not supported)", dir.UserConfigDir, fileName)
46 var config string
47 err := load(fileName, &config)
48 if err != nil && err.Error() != expectedError {
49 t.Fatalf("load() expected error= %s but found= %v", expectedError, err)
50 }
51 }