-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
98 lines (86 loc) · 2.62 KB
/
Copy pathconfig_test.go
File metadata and controls
98 lines (86 loc) · 2.62 KB
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
package config
import (
"strings"
"testing"
)
func TestLoadDefaultsToWherobotsOpenAPISpec(t *testing.T) {
t.Setenv("WHEROBOTS_API_URL", "")
t.Setenv("WHEROBOTS_API_KEY", "key-1")
t.Setenv("WHEROBOTS_UPLOAD_PATH", "")
cfg, err := Load()
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.AppName != "wherobots" {
t.Fatalf("AppName = %q, want %q", cfg.AppName, "wherobots")
}
if cfg.OpenAPIURL != "https://api.cloud.wherobots.com/openapi.json" {
t.Fatalf("OpenAPIURL = %q", cfg.OpenAPIURL)
}
if cfg.APIKey != "key-1" {
t.Fatalf("APIKey = %q, want %q", cfg.APIKey, "key-1")
}
if cfg.UploadPath != "" {
t.Fatalf("UploadPath = %q, want empty", cfg.UploadPath)
}
}
func TestLoadBuildsSpecURLFromWherobotsAPIURL(t *testing.T) {
t.Setenv("WHEROBOTS_API_URL", "https://api.example.com")
t.Setenv("WHEROBOTS_API_KEY", "key-1")
cfg, err := Load()
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.OpenAPIURL != "https://api.example.com/openapi.json" {
t.Fatalf("OpenAPIURL = %q, want %q", cfg.OpenAPIURL, "https://api.example.com/openapi.json")
}
}
func TestLoadSucceedsWithoutAPIKey(t *testing.T) {
t.Setenv("WHEROBOTS_API_URL", "")
t.Setenv("WHEROBOTS_API_KEY", "")
cfg, err := Load()
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.APIKey != "" {
t.Fatalf("APIKey = %q, want empty", cfg.APIKey)
}
}
func TestRequireAPIKeyErrorsWithDefaultURL(t *testing.T) {
cfg := Config{OpenAPIURL: "https://api.cloud.wherobots.com/openapi.json"}
err := cfg.RequireAPIKey()
if err == nil {
t.Fatalf("expected error")
}
if !strings.Contains(err.Error(), "https://cloud.wherobots.com/settings#api-keys") {
t.Fatalf("error should contain default API key URL, got: %v", err)
}
}
func TestRequireAPIKeyErrorsWithCustomURL(t *testing.T) {
cfg := Config{OpenAPIURL: "https://api.staging.wherobots.com/openapi.json"}
err := cfg.RequireAPIKey()
if err == nil {
t.Fatalf("expected error")
}
if !strings.Contains(err.Error(), "https://staging.wherobots.com/settings#api-keys") {
t.Fatalf("error should contain custom API key URL, got: %v", err)
}
}
func TestRequireAPIKeySucceedsWithKey(t *testing.T) {
cfg := Config{APIKey: "key-1"}
if err := cfg.RequireAPIKey(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
func TestLoadReadsUploadPathConfig(t *testing.T) {
t.Setenv("WHEROBOTS_API_URL", "")
t.Setenv("WHEROBOTS_API_KEY", "key-1")
t.Setenv("WHEROBOTS_UPLOAD_PATH", "s3://override-bucket/custom/root")
cfg, err := Load()
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.UploadPath != "s3://override-bucket/custom/root" {
t.Fatalf("UploadPath = %q", cfg.UploadPath)
}
}