Skip to content

Commit

Permalink
fix: resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao committed Feb 8, 2023
1 parent 2fa2a90 commit 77bc3af
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 28 deletions.
4 changes: 0 additions & 4 deletions pkg/configutil/once.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var (
// configInfo is the config.json data
configInfo *config.Config
configOnce sync.Once

// signingKeyInfo if the signingkeys.json data
signingKeysInfo *config.SigningKeys
signingKeysOnce sync.Once
)

// LoadConfigOnce returns the previously read config file.
Expand Down
2 changes: 0 additions & 2 deletions pkg/configutil/once_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package configutil

import (
"sync"
"testing"
)

Expand All @@ -17,5 +16,4 @@ func TestLoadConfigOnce(t *testing.T) {
if config1 != config2 {
t.Fatal("LoadConfigOnce is invalid.")
}
configOnce = sync.Once{}
}
2 changes: 1 addition & 1 deletion pkg/configutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func ResolveKey(name string) (config.KeySuite, error) {
if err != nil {
return config.KeySuite{}, err
}

// if name is empty, look for default signing key
if name == "" {
return signingKeys.GetDefault()
}

return signingKeys.Get(name)
}
23 changes: 2 additions & 21 deletions pkg/configutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestIsRegistryInsecure(t *testing.T) {
configOnce = sync.Once{}
// for restore dir
defer func(oldDir string) {
dir.UserConfigDir = oldDir
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestIsRegistryInsecure(t *testing.T) {
}

func TestIsRegistryInsecureMissingConfig(t *testing.T) {
configOnce = sync.Once{}
// for restore dir
defer func(oldDir string) {
dir.UserConfigDir = oldDir
Expand Down Expand Up @@ -94,7 +96,6 @@ func TestIsRegistryInsecureConfigPermissionError(t *testing.T) {
func TestResolveKey(t *testing.T) {
defer func(oldDir string) {
dir.UserConfigDir = oldDir
signingKeysOnce = sync.Once{}
}(dir.UserConfigDir)

t.Run("valid e2e key", func(t *testing.T) {
Expand All @@ -106,7 +107,6 @@ func TestResolveKey(t *testing.T) {
if keySuite.Name != "e2e" {
t.Error("key name is not correct.")
}
signingKeysOnce = sync.Once{}
})

t.Run("key name is empty (using default key)", func(t *testing.T) {
Expand All @@ -118,25 +118,6 @@ func TestResolveKey(t *testing.T) {
if keySuite.Name != "e2e" {
t.Error("key name is not correct.")
}
signingKeysOnce = sync.Once{}
})

t.Run("key name doesn't exist", func(t *testing.T) {
dir.UserConfigDir = "./testdata/valid_signingkeys"
_, err := ResolveKey("e2e2")
if !strings.Contains(err.Error(), "signing key not found") {
t.Error("should error")
}
signingKeysOnce = sync.Once{}
})

t.Run("key name is empty (no default key)", func(t *testing.T) {
dir.UserConfigDir = "./testdata/no_default_key_signingkeys"
_, err := ResolveKey("")
if !strings.Contains(err.Error(), "default signing key not set.") {
t.Error("should error")
}
signingKeysOnce = sync.Once{}
})

t.Run("signingkeys.json without read permission", func(t *testing.T) {
Expand Down

0 comments on commit 77bc3af

Please sign in to comment.