-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from lucaslorentz/merge_php_fastcgi
Merge php_fastcgi
- Loading branch information
Showing
8 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package caddyfile | ||
|
||
import ( | ||
"io/ioutil" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
_ "github.com/caddyserver/caddy/v2/modules/standard" // plug standard HTTP modules | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMerge(t *testing.T) { | ||
const folder = "./testdata/merge" | ||
|
||
// load the list of test files from the dir | ||
files, err := ioutil.ReadDir(folder) | ||
if err != nil { | ||
t.Errorf("failed to read process dir: %s", err) | ||
} | ||
|
||
// prep a regexp to fix strings on windows | ||
winNewlines := regexp.MustCompile(`\r?\n`) | ||
|
||
for _, f := range files { | ||
if f.IsDir() { | ||
continue | ||
} | ||
|
||
// read the test file | ||
filename := f.Name() | ||
|
||
t.Run(filename, func(t *testing.T) { | ||
data, err := ioutil.ReadFile(folder + "/" + filename) | ||
if err != nil { | ||
t.Errorf("failed to read %s dir: %s", filename, err) | ||
} | ||
|
||
// replace windows newlines in the json with unix newlines | ||
content := winNewlines.ReplaceAllString(string(data), "\n") | ||
|
||
// split two Caddyfile parts | ||
parts := strings.Split(content, "----------\n") | ||
caddyfile1, caddyfile2, expectedCaddyfile := parts[0], parts[1], parts[2] | ||
|
||
container1, _ := Unmarshal([]byte(caddyfile1)) | ||
container2, _ := Unmarshal([]byte(caddyfile2)) | ||
|
||
container1.Merge(container2) | ||
|
||
result := string(container1.Marshal()) | ||
|
||
actualCaddyfile := string(result) | ||
|
||
// compare the actual and expected Caddyfiles | ||
assert.Equal(t, expectedCaddyfile, actualCaddyfile, | ||
"failed to process in %s", filename) | ||
}) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
plugin/caddyfile/testdata/merge/php_fastcgi_different_matcher.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
example.com { | ||
php_fastcgi /a service-a:80 | ||
} | ||
---------- | ||
example.com { | ||
php_fastcgi /b service-b:81 | ||
} | ||
---------- | ||
example.com { | ||
php_fastcgi /a service-a:80 | ||
php_fastcgi /b service-b:81 | ||
} |
11 changes: 11 additions & 0 deletions
11
plugin/caddyfile/testdata/merge/php_fastcgi_no_matcher.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
example.com { | ||
php_fastcgi service-a:80 | ||
} | ||
---------- | ||
example.com { | ||
php_fastcgi service-b:81 | ||
} | ||
---------- | ||
example.com { | ||
php_fastcgi service-a:80 service-b:81 | ||
} |
11 changes: 11 additions & 0 deletions
11
plugin/caddyfile/testdata/merge/php_fastcgi_same_matcher.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
example.com { | ||
php_fastcgi /path service-a:80 | ||
} | ||
---------- | ||
example.com { | ||
php_fastcgi /path service-b:81 | ||
} | ||
---------- | ||
example.com { | ||
php_fastcgi /path service-a:80 service-b:81 | ||
} |
12 changes: 12 additions & 0 deletions
12
plugin/caddyfile/testdata/merge/reverse_proxy_different_matcher.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
example.com { | ||
reverse_proxy /a service-a:80 | ||
} | ||
---------- | ||
example.com { | ||
reverse_proxy /b service-b:81 | ||
} | ||
---------- | ||
example.com { | ||
reverse_proxy /a service-a:80 | ||
reverse_proxy /b service-b:81 | ||
} |
11 changes: 11 additions & 0 deletions
11
plugin/caddyfile/testdata/merge/reverse_proxy_no_matcher.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
example.com { | ||
reverse_proxy service-a:80 | ||
} | ||
---------- | ||
example.com { | ||
reverse_proxy service-b:81 | ||
} | ||
---------- | ||
example.com { | ||
reverse_proxy service-a:80 service-b:81 | ||
} |
11 changes: 11 additions & 0 deletions
11
plugin/caddyfile/testdata/merge/reverse_proxy_same_matcher.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
example.com { | ||
reverse_proxy /path service-a:80 | ||
} | ||
---------- | ||
example.com { | ||
reverse_proxy /path service-b:81 | ||
} | ||
---------- | ||
example.com { | ||
reverse_proxy /path service-a:80 service-b:81 | ||
} |