-
Notifications
You must be signed in to change notification settings - Fork 385
/
envconfig_1.8_test.go
68 lines (53 loc) · 1.38 KB
/
envconfig_1.8_test.go
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
// +build go1.8
package envconfig
import (
"errors"
"net/url"
"os"
"testing"
)
type SpecWithURL struct {
UrlValue url.URL
UrlPointer *url.URL
}
func TestParseURL(t *testing.T) {
var s SpecWithURL
os.Clearenv()
os.Setenv("ENV_CONFIG_URLVALUE", "https://github.com/kelseyhightower/envconfig")
os.Setenv("ENV_CONFIG_URLPOINTER", "https://github.com/kelseyhightower/envconfig")
err := Process("env_config", &s)
if err != nil {
t.Fatal("unexpected error:", err)
}
u, err := url.Parse("https://github.com/kelseyhightower/envconfig")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if s.UrlValue != *u {
t.Errorf("expected %q, got %q", u, s.UrlValue.String())
}
if *s.UrlPointer != *u {
t.Errorf("expected %q, got %q", u, s.UrlPointer)
}
}
func TestParseURLError(t *testing.T) {
var s SpecWithURL
os.Clearenv()
os.Setenv("ENV_CONFIG_URLPOINTER", "http_://foo")
err := Process("env_config", &s)
v, ok := err.(*ParseError)
if !ok {
t.Fatalf("expected ParseError, got %T %v", err, err)
}
if v.FieldName != "UrlPointer" {
t.Errorf("expected %s, got %v", "UrlPointer", v.FieldName)
}
expectedUnerlyingError := url.Error{
Op: "parse",
URL: "http_://foo",
Err: errors.New("first path segment in URL cannot contain colon"),
}
if v.Err.Error() != expectedUnerlyingError.Error() {
t.Errorf("expected %q, got %q", expectedUnerlyingError, v.Err)
}
}