GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DockerImageSave/config_test.go at master · jadolg/DockerImageSave

Expand file tree

/

config_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
153 lines (131 loc) · 3.43 KB
/

config_test.go

Copy path

File metadata and controls

153 lines (131 loc) · 3.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"os"
"path/filepath"
"testing"
)
func TestLoadConfig(t *testing.T) {
tempDir, err := os.MkdirTemp("", "config-test-*")
if err != nil {
t.Fatal(err)
}
defer cleanupTempDir(t, tempDir)
configContent := `
port: 9090
cache_dir: /var/cache/images
registries:
ghcr.io:
username: testuser
password: testpass
registry.example.com:
username: admin
password: secret
`
configPath := filepath.Join(tempDir, "config.yaml")
if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
t.Fatal(err)
}
config, err := LoadConfig(configPath)
if err != nil {
t.Fatalf("failed to load config: %v", err)
}
if config.Port != 9090 {
t.Errorf("expected port 9090, got %d", config.Port)
}
if config.CacheDir != "/var/cache/images" {
t.Errorf("expected cache_dir '/var/cache/images', got '%s'", config.CacheDir)
}
if len(config.Registries) != 2 {
t.Errorf("expected 2 registries, got %d", len(config.Registries))
}
ghcrCreds, ok := config.Registries["ghcr.io"]
if !ok {
t.Error("expected ghcr.io registry credentials")
} else {
if ghcrCreds.Username != "testuser" {
t.Errorf("expected username 'testuser', got '%s'", ghcrCreds.Username)
}
if ghcrCreds.Password != "testpass" {
t.Errorf("expected password 'testpass', got '%s'", ghcrCreds.Password)
}
}
}
func TestLoadConfig_Defaults(t *testing.T) {
tempDir, err := os.MkdirTemp("", "config-test-*")
if err != nil {
t.Fatal(err)
}
defer cleanupTempDir(t, tempDir)
configContent := `{}`
configPath := filepath.Join(tempDir, "config.yaml")
if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
t.Fatal(err)
}
config, err := LoadConfig(configPath)
if err != nil {
t.Fatalf("failed to load config: %v", err)
}
if config.Port != 8080 {
t.Errorf("expected default port 8080, got %d", config.Port)
}
}
func TestLoadConfig_InvalidPort(t *testing.T) {
tempDir, err := os.MkdirTemp("", "config-test-*")
if err != nil {
t.Fatal(err)
}
defer cleanupTempDir(t, tempDir)
configContent := `port: 99999`
configPath := filepath.Join(tempDir, "config.yaml")
if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
t.Fatal(err)
}
_, err = LoadConfig(configPath)
if err == nil {
t.Error("expected error for invalid port")
}
}
func TestLoadConfig_MissingFile(t *testing.T) {
_, err := LoadConfig("/nonexistent/config.yaml")
if err == nil {
t.Error("expected error for missing file")
}
}
func TestLoadConfig_InvalidYAML(t *testing.T) {
tempDir, err := os.MkdirTemp("", "config-test-*")
if err != nil {
t.Fatal(err)
}
defer cleanupTempDir(t, tempDir)
configContent := `invalid: yaml: content: [`
configPath := filepath.Join(tempDir, "config.yaml")
if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
t.Fatal(err)
}
_, err = LoadConfig(configPath)
if err == nil {
t.Error("expected error for invalid YAML")
}
}
func TestApplyCredentials(t *testing.T) {
config := &Config{
Port: 8080,
Registries: map[string]RegistryConfig{
"ghcr.io": {
Username: "testuser",
Password: "testpass",
},
},
}
config.ApplyCredentials()
creds, ok := GetCredentials("ghcr.io")
if !ok {
t.Error("expected credentials for ghcr.io")
}
if creds.Username != "testuser" {
t.Errorf("expected username 'testuser', got '%s'", creds.Username)
}
if creds.Password != "testpass" {
t.Errorf("expected password 'testpass', got '%s'", creds.Password)
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.