Skip to content

Commit

Permalink
Add default Github stuff (#1)
Browse files Browse the repository at this point in the history
* Add default Github stuff

* Add Executable Permissions

* Change Port random during tests

* Add Lazy testing
  • Loading branch information
furkilic authored May 14, 2020
1 parent e523c11 commit 26d620b
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 22 deletions.
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: "[Bug]"
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**please complete the following information:**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]


**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[Feature]"
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
35 changes: 35 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.14
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: ./scripts/build.sh

- name: Test
run: ./scripts/test.sh

- name: Bench
run: ./scripts/bench.sh

- name: Lint
run: ./scripts/analysis.sh
Empty file modified gow
100644 → 100755
Empty file.
50 changes: 28 additions & 22 deletions pkg/go-boot-web/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/gorilla/mux"
"io/ioutil"
"log"
"math/rand"
"net/http"
"reflect"
"strings"
Expand All @@ -21,6 +22,7 @@ import (
)

func Test_web(t *testing.T) {
rand.Seed(time.Now().UnixNano())
type req struct {
url string
headers map[string]string
Expand All @@ -34,42 +36,42 @@ func Test_web(t *testing.T) {
err bool
}
defaultWebConf := GoWebConf{
":8080",
":0000",
0,
"",
1 << 20,
60000,
15000,
15000,
15000,
5,
Compression{false},
NotFoundHandler{true},
HTTP2{false},
SSL{false, "", ""},
}
httpsConf := GoWebConf{
":8080",
":0000",
0,
"",
1 << 20,
60000,
15000,
15000,
15000,
5,
Compression{false},
NotFoundHandler{true},
HTTP2{true},
SSL{true, "../../test/cert.pem", "../../test/key.pem"},
}
errorConf := GoWebConf{
":8080",
":0000",
0,
"",
16,
100,
100,
100,
15000,
5,
Compression{false},
NotFoundHandler{true},
HTTP2{false},
Expand All @@ -90,7 +92,7 @@ func Test_web(t *testing.T) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode("NoNo")
},
req{"http://localhost:8080/none", createMap(), false, false},
req{"http://localhost:0000/none", createMap(), false, false},
resp{
"HTTP/1.1",
http.StatusOK,
Expand All @@ -100,14 +102,14 @@ func Test_web(t *testing.T) {
},
{"With BasePath",
GoWebConf{
":9090",
":0000",
0,
"/base-path",
1 << 20,
60000,
15000,
15000,
15000,
5,
Compression{false},
NotFoundHandler{true},
HTTP2{false},
Expand All @@ -118,7 +120,7 @@ func Test_web(t *testing.T) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode("BasePath")
},
req{"http://localhost:9090/base-path/basePath", createMap(), false, false},
req{"http://localhost:0000/base-path/basePath", createMap(), false, false},
resp{
"HTTP/1.1",
http.StatusOK,
Expand All @@ -128,14 +130,14 @@ func Test_web(t *testing.T) {
},
{"With Compression",
GoWebConf{
":8080",
":0000",
0,
"",
1 << 20,
60000,
15000,
15000,
15000,
5,
Compression{true},
NotFoundHandler{true},
HTTP2{false},
Expand All @@ -146,7 +148,7 @@ func Test_web(t *testing.T) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode("Compressed")
},
req{"http://localhost:8080/compressed", createMap("Accept-Encoding", "gzip"), false, false},
req{"http://localhost:0000/compressed", createMap("Accept-Encoding", "gzip"), false, false},
resp{
"HTTP/1.1",
http.StatusOK,
Expand All @@ -157,7 +159,7 @@ func Test_web(t *testing.T) {
{"NotFound Default Handler",
defaultWebConf, "none",
nil,
req{"http://localhost:8080/not-found", createMap(), false, false},
req{"http://localhost:0000/not-found", createMap(), false, false},
resp{
"HTTP/1.1",
http.StatusNotFound,
Expand All @@ -168,7 +170,7 @@ func Test_web(t *testing.T) {
{"NotFound JSON Handler",
defaultWebConf, "none",
nil,
req{"http://localhost:8080/not-found", createMap("Accept", "application/json"), false, false},
req{"http://localhost:0000/not-found", createMap("Accept", "application/json"), false, false},
resp{
"HTTP/1.1",
http.StatusNotFound,
Expand All @@ -179,7 +181,7 @@ func Test_web(t *testing.T) {
{"NotFound XML Handler",
defaultWebConf, "none",
nil,
req{"http://localhost:8080/not-found", createMap("Accept", "application/xml"), false, false},
req{"http://localhost:0000/not-found", createMap("Accept", "application/xml"), false, false},
resp{
"HTTP/1.1",
http.StatusNotFound,
Expand All @@ -190,7 +192,7 @@ func Test_web(t *testing.T) {
{"NotFound HTML Handler",
defaultWebConf, "none",
nil,
req{"http://localhost:8080/not-found", createMap("Accept", "text/html"), false, false},
req{"http://localhost:0000/not-found", createMap("Accept", "text/html"), false, false},
resp{
"HTTP/1.1",
http.StatusNotFound,
Expand All @@ -205,7 +207,7 @@ func Test_web(t *testing.T) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode("HTTPS")
},
req{"https://localhost:8080/https", createMap(), true, false},
req{"https://localhost:0000/https", createMap(), true, false},
resp{
"HTTP/1.1",
http.StatusOK,
Expand All @@ -220,7 +222,7 @@ func Test_web(t *testing.T) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode("HTTP2")
},
req{"https://localhost:8080/http2", createMap(), true, true},
req{"https://localhost:0000/http2", createMap(), true, true},
resp{
"HTTP/2.0",
http.StatusOK,
Expand All @@ -231,7 +233,7 @@ func Test_web(t *testing.T) {
{"Error Big Header",
errorConf, "error",
func(w http.ResponseWriter, r *http.Request) { time.Sleep(time.Second * 1) },
req{"http://localhost:8080/error",
req{"http://localhost:0000/error",
func() map[string]string {
m := make(map[string]string)
for i := 0; i < 1000; i++ {
Expand All @@ -255,7 +257,7 @@ func Test_web(t *testing.T) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode("toto")
},
req{"http://localhost:8080/error", createMap(),
req{"http://localhost:0000/error", createMap(),
false, false},
resp{
"",
Expand All @@ -267,10 +269,14 @@ func Test_web(t *testing.T) {
}

for _, tt := range tests {
port := rand.Intn(1010) + 8080
router = mux.NewRouter().StrictSlash(true)
goWebConf = tt.conf
goWebConf.Address = fmt.Sprintf(":%d", port)
tt.req.url = strings.ReplaceAll(tt.req.url, ":0000", goWebConf.Address)
addDefaultValues()
Start()
time.Sleep(time.Millisecond * 100)
Router().Methods("GET").Path("/" + tt.path).Name(strings.ToUpper(tt.path)).HandlerFunc(tt.handler)
t.Run(tt.name, func(t *testing.T) {
proto, status, response, err := call(tt.req.url, tt.req.headers, tt.req.https, tt.req.http2)
Expand All @@ -289,7 +295,7 @@ func Test_web(t *testing.T) {
t.Errorf("web() = %v, want %v", r, tt.resp)
}
})
fmt.Println(Stop())
Stop()
}
}

Expand Down
Empty file modified scripts/analysis.sh
100644 → 100755
Empty file.
Empty file modified scripts/bench.sh
100644 → 100755
Empty file.
Empty file modified scripts/build.sh
100644 → 100755
Empty file.
Empty file modified scripts/common.sh
100644 → 100755
Empty file.
Empty file modified scripts/docker-build.sh
100644 → 100755
Empty file.
Empty file modified scripts/docker-compose-up.sh
100644 → 100755
Empty file.
Empty file modified scripts/fmt.sh
100644 → 100755
Empty file.
Empty file modified scripts/test.sh
100644 → 100755
Empty file.

0 comments on commit 26d620b

Please sign in to comment.