This repository was archived by the owner on Aug 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_test.go
More file actions
97 lines (66 loc) · 1.96 KB
/
string_test.go
File metadata and controls
97 lines (66 loc) · 1.96 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
package runtimevar
import (
"context"
"fmt"
"net/url"
"path/filepath"
"testing"
)
func TestConstantVar(t *testing.T) {
ctx := context.Background()
tests := map[string]string{
"constant://?val=hello+world": "hello world",
"/foo/bar/baz": "/foo/bar/baz",
"test": "test",
}
for uri, expected := range tests {
str_var, err := StringVar(ctx, uri)
if err != nil {
t.Fatalf("Failed to retrieve string var for '%s', %v", uri, err)
}
if str_var != expected {
t.Fatalf("Unexpected result for '%s'. Expected '%s' but got '%s'", uri, expected, str_var)
}
}
}
func TestFileVar(t *testing.T) {
ctx := context.Background()
tests := map[string]string{
"fixtures/helloworld.txt": "hello world\n",
}
for rel_path, expected := range tests {
abs_path, err := filepath.Abs(rel_path)
if err != nil {
t.Fatalf("Failed to determine absolute path for '%s', %v", rel_path, err)
}
uri := fmt.Sprintf("file://%s?decoder=string", abs_path)
str_var, err := StringVar(ctx, uri)
if err != nil {
t.Fatalf("Failed to retrieve string var for '%s', %v", uri, err)
}
if str_var != expected {
t.Fatalf("Unexpected result for '%s'. Expected '%s' but got '%s'", uri, expected, str_var)
}
}
}
func TestBlobVar(t *testing.T) {
ctx := context.Background()
abs_fixtures, err := filepath.Abs("fixtures")
if err != nil {
t.Fatalf("Failed to derive absolute path for fixtures, %v", err)
}
bucket_uri := fmt.Sprintf("file://%s", abs_fixtures)
bucket_uri = url.QueryEscape(bucket_uri)
tests := map[string]string{
fmt.Sprintf("blobvar://helloworld.txt?bucket-uri=%s&decoder=string", bucket_uri): "hello world\n",
}
for uri, expected := range tests {
str_var, err := StringVar(ctx, uri)
if err != nil {
t.Fatalf("Failed to retrieve string var for '%s', %v", uri, err)
}
if str_var != expected {
t.Fatalf("Unexpected result for '%s'. Expected '%s' but got '%s'", uri, expected, str_var)
}
}
}