Debian Codegraph @

config/config_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 "reflect"
18 "testing"
19
20 "github.com/notaryproject/notation-go/dir"
21 )
22
23 var sampleConfig = &Config{
24 InsecureRegistries: []string{
25 "registry.wabbit-networks.io",
26 },
27 SignatureFormat: "jws",
28 }
29
30 func TestLoadFile(t *testing.T) {
31 dir.UserConfigDir = "./testdata/valid"
32 got, err := LoadConfig()
33 if err != nil {
34 t.Fatalf("LoadConfig() error. err = %v", err)
35 }
36
37 if !reflect.DeepEqual(got, sampleConfig) {
38 t.Errorf("loadFile() = %v, want %v", got, sampleConfig)
39 }
40 }
41
42 func TestSaveFile(t *testing.T) {
43 root := t.TempDir()
44 dir.UserConfigDir = root
45 sampleConfig.Save()
46 config, err := LoadConfig()
47 if err != nil {
48 t.Fatal("Load config file from temp dir failed")
49 }
50 if !reflect.DeepEqual(sampleConfig, config) {
51 t.Fatal("save config file failed.")
52 }
53 }
54
55 func TestLoadNonExistedConfig(t *testing.T) {
56 dir.UserConfigDir = "./testdata/non-existed"
57 got, err := LoadConfig()
58 if err != nil {
59 t.Fatalf("LoadConfig() error. err = %v", err)
60 }
61
62 if !reflect.DeepEqual(got, NewConfig()) {
63 t.Errorf("loadFile() = %v, want %v", got, NewConfig())
64 }
65 }