From 3d1a52d6f332b0a2b4f40463835d047cef5c36f7 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 18:10:24 +0530 Subject: [PATCH 01/21] add `.github/workflows/pipeline.yml` file to run test cases on diff os --- .github/workflows/pipeline.yml | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/pipeline.yml diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 00000000..419fa971 --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,56 @@ +# This is a basic workflow to help you get started with Actions + +name: Continous Integration + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: + - master + - staging + - develop + pull_request: + branches: + - master + - staging + - develop + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # The "build" workflow + build: + # The type of runner that the job will run on + runs-on: [macos-latest, ubuntu-latest, windows-latest] + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Setup Go + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.18.0' # The Go version to download (if necessary) and use. + + # Install all the dependencies + - name: Install dependencies + run: | + go version + go get -u golang.org/x/lint/golint + + # Run build of the application + - name: Run build + run: go build . + + # Run vet & lint on the code + - name: Run vet & lint + run: | + go vet . + golint . + + # Run testing on the code + - name: Run test suites + run: go test -v + From 900686dbc485b276bdcac987838d7ee2592fb4c5 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 20:58:14 +0530 Subject: [PATCH 02/21] remove other os and keep windows-latest --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 419fa971..480a12fc 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,7 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: [macos-latest, ubuntu-latest, windows-latest] + runs-on: windows-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: From 5d6b912605bb7a1c840f0d1dd105778e726a860f Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 21:03:01 +0530 Subject: [PATCH 03/21] remove `golint` from github actions --- .github/workflows/pipeline.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 480a12fc..08d4e7bd 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -48,7 +48,6 @@ jobs: - name: Run vet & lint run: | go vet . - golint . # Run testing on the code - name: Run test suites From f0c49adb89ae39ce8d1befe028bbf25a88a75d92 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 21:22:28 +0530 Subject: [PATCH 04/21] add `linux` and `macos` as runners --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 08d4e7bd..163b74b4 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,7 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: windows-latest + runs-on: [windows-latest, ubuntu-latest, macos-latest] # Steps represent a sequence of tasks that will be executed as part of the job steps: From ad2688d03efc43b9a97c7b6a24823dc68e82274e Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 21:26:58 +0530 Subject: [PATCH 05/21] remove `macos` as runner --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 163b74b4..2684787f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,7 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: [windows-latest, ubuntu-latest, macos-latest] + runs-on: [windows-latest, ubuntu-latest] # Steps represent a sequence of tasks that will be executed as part of the job steps: From b1f3adf9db486b514b97226300c3299696cea17b Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 21:31:11 +0530 Subject: [PATCH 06/21] remove `ubuntu-latest` as runner --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 2684787f..27547136 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,7 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: [windows-latest, ubuntu-latest] + runs-on: [windows-latest] # Steps represent a sequence of tasks that will be executed as part of the job steps: From 243c2c16ed520745bb9118880f6dcaf05e5319af Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 21:32:27 +0530 Subject: [PATCH 07/21] add `ubuntu-latest` as runner --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 27547136..2684787f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,7 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: [windows-latest] + runs-on: [windows-latest, ubuntu-latest] # Steps represent a sequence of tasks that will be executed as part of the job steps: From f1ea8c7a1937cb882166a24a0ca4cbb6414fcab7 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 21:36:10 +0530 Subject: [PATCH 08/21] remove `latest` from `ubuntu` runner name --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 2684787f..c61dd931 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,7 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: [windows-latest, ubuntu-latest] + runs-on: [windows-latest, ubuntu-20.04] # Steps represent a sequence of tasks that will be executed as part of the job steps: From cc017bc393ae126d3eb19a5ab3e52528c93a26e6 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 22:39:05 +0530 Subject: [PATCH 09/21] add quotes to the runners array element --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index c61dd931..582a98bf 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,7 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: [windows-latest, ubuntu-20.04] + runs-on: ['windows-latest', 'ubuntu-20.04'] # Steps represent a sequence of tasks that will be executed as part of the job steps: From 84776a4f6033a1e174e14beef0a42e8084749568 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Tue, 31 May 2022 22:51:45 +0530 Subject: [PATCH 10/21] fix pipeline to run on multiple os --- .github/workflows/pipeline.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 582a98bf..6ed637da 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -21,7 +21,10 @@ jobs: # The "build" workflow build: # The type of runner that the job will run on - runs-on: ['windows-latest', 'ubuntu-20.04'] + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] # Steps represent a sequence of tasks that will be executed as part of the job steps: From 35cd00a8d564a9dae496319bdfc8af624a17703b Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Wed, 1 Jun 2022 01:19:13 +0530 Subject: [PATCH 11/21] add test case to reproduce `filepath.Abs` err on windows --- mux_httpserver_test.go | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index 907ab91d..6c4974d9 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -8,6 +8,8 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "os" + "path/filepath" "testing" ) @@ -48,3 +50,81 @@ func TestSchemeMatchers(t *testing.T) { assertResponseBody(t, s, "hello https world") }) } + +// spaHandler implements the http.Handler interface, so we can use it +// to respond to HTTP requests. The path to the static directory and +// path to the index file within that static directory are used to +// serve the SPA in the given static directory. +type spaHandler struct { + staticPath string + indexPath string +} + +// ServeHTTP inspects the URL path to locate a file within the static dir +// on the SPA handler. If a file is found, it will be served. If not, the +// file located at the index path on the SPA handler will be served. This +// is suitable behavior for serving an SPA (single page application). +func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // get the absolute path to prevent directory traversal + path, err := filepath.Abs(r.URL.Path) + if err != nil { + // if we failed to get the absolute path respond with a 400 bad request + // and stop + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + // prepend the path with the path to the static directory + path = filepath.Join(h.staticPath, path) + + // check whether a file exists at the given path + _, err = os.Stat(path) + + if os.IsNotExist(err) { + // file does not exist, serve index.html + http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath)) + return + } else if err != nil { + // if we got an error (that wasn't that the file doesn't exist) stating the + // file, return a 500 internal server error and stop + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // otherwise, use http.FileServer to serve the static dir + http.FileServer(http.Dir(h.staticPath)).ServeHTTP(w, r) +} + +func TestCustomServeHttp(t *testing.T) { + // create a build directory and write a `index.html` file + os.Mkdir("build", 0700) + + htmlContent := []byte(`helloworld`) + + err := os.WriteFile("./build/index.html", htmlContent, 0700) + if err != nil { + t.Fatal(err) + } + + req, err := http.NewRequest("GET", "/", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + spa := spaHandler{staticPath: "./build", indexPath: "index.html"} + spa.ServeHTTP(rr, req) + + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusOK) + } + + // Check the response body is what we expect. + if rr.Body.String() != string(htmlContent) { + t.Errorf("handler returned unexpected body: got %v want %v", + rr.Body.String(), string(htmlContent)) + } + +} From 4f0d6a32d7cddcd875e80f604c836a6d04d06eb6 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Wed, 1 Jun 2022 01:29:33 +0530 Subject: [PATCH 12/21] add `concurrency` property to `pipeline.yml` --- .github/workflows/pipeline.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 6ed637da..7363c95f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -16,6 +16,13 @@ on: - staging - develop +# Cancels all previous workflow runs for pull requests that have not completed. +concurrency: + # The concurrency group contains the workflow name and the branch name for pull requests + # or the commit hash for any other events. + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # The "build" workflow From 762ae158e1c890ffa261dda9841d35fdb0e70c5d Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Wed, 1 Jun 2022 01:52:42 +0530 Subject: [PATCH 13/21] replace `filepath.Abs` with `filepath.Join` inside `ServeHTTP` --- mux_httpserver_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index 6c4974d9..3017403c 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -66,7 +66,8 @@ type spaHandler struct { // is suitable behavior for serving an SPA (single page application). func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // get the absolute path to prevent directory traversal - path, err := filepath.Abs(r.URL.Path) + var err error + path := filepath.Join(h.staticPath, r.URL.Path) if err != nil { // if we failed to get the absolute path respond with a 400 bad request // and stop From 1ef820e180f4e6d0c87751f648165062bc8e8216 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Wed, 1 Jun 2022 02:06:06 +0530 Subject: [PATCH 14/21] comment 2nd occurance of filepath.join --- mux_httpserver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index 3017403c..153eaaf4 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -76,7 +76,7 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // prepend the path with the path to the static directory - path = filepath.Join(h.staticPath, path) + // path = filepath.Join(h.staticPath, path) // check whether a file exists at the given path _, err = os.Stat(path) From fa25f03885e68990af694fcc394539152126b1c8 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Wed, 1 Jun 2022 15:04:14 +0530 Subject: [PATCH 15/21] add test case negative and positive for `SPA` filepath.Abs err on windows --- mux_httpserver_test.go | 158 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index 907ab91d..8faf75bd 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -8,9 +8,92 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "os" + "path/filepath" + "runtime" + "strings" "testing" ) +// spaHandler implements the http.Handler interface, so we can use it +// to respond to HTTP requests. The path to the static directory and +// path to the index file within that static directory are used to +// serve the SPA in the given static directory. +type spaHandler struct { + staticPath string + indexPath string +} + +// FilepathAbsServeHTTP inspects the URL path to locate a file within the static dir +// on the SPA handler. If a file is found, it will be served. If not, the +// file located at the index path on the SPA handler will be served. This +// is suitable behavior for serving an SPA (single page application). +// This is a negative test case where `filepath.Abs` will return path value like `D:\` +// if our route is `/`. As per docs: Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result. +func (h spaHandler) FilepathAbsServeHTTP(w http.ResponseWriter, r *http.Request) { + // get the absolute path to prevent directory traversal + path, err := filepath.Abs(r.URL.Path) + if err != nil { + // if we failed to get the absolute path respond with a 400 bad request + // and stop + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + // prepend the path with the path to the static directory + // path = filepath.Join(h.staticPath, path) + + // check whether a file exists at the given path + _, err = os.Stat(path) + + if os.IsNotExist(err) { + // file does not exist, serve index.html + http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath)) + return + } else if err != nil { + // if we got an error (that wasn't that the file doesn't exist) stating the + // file, return a 500 internal server error and stop + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // otherwise, use http.FileServer to serve the static dir + http.FileServer(http.Dir(h.staticPath)).ServeHTTP(w, r) +} + +// ServeHTTP inspects the URL path to locate a file within the static dir +// on the SPA handler. If a file is found, it will be served. If not, the +// file located at the index path on the SPA handler will be served. This +// is suitable behavior for serving an SPA (single page application). +func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // get the absolute path to prevent directory traversal + var err error + path := filepath.Join(h.staticPath, r.URL.Path) + if err != nil { + // if we failed to get the absolute path respond with a 400 bad request + // and stop + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + // check whether a file exists at the given path + _, err = os.Stat(path) + + if os.IsNotExist(err) { + // file does not exist, serve index.html + http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath)) + return + } else if err != nil { + // if we got an error (that wasn't that the file doesn't exist) stating the + // file, return a 500 internal server error and stop + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // otherwise, use http.FileServer to serve the static dir + http.FileServer(http.Dir(h.staticPath)).ServeHTTP(w, r) +} + func TestSchemeMatchers(t *testing.T) { router := NewRouter() router.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { @@ -48,3 +131,78 @@ func TestSchemeMatchers(t *testing.T) { assertResponseBody(t, s, "hello https world") }) } + +func TestServeHttpFilepathAbs(t *testing.T) { + // create a diretory name `build` + os.Mkdir("build", 0700) + + // create a file `index.html` and write below content + htmlContent := []byte(`helloworld`) + err := os.WriteFile("./build/index.html", htmlContent, 0700) + if err != nil { + t.Fatal(err) + } + + // make new request + req, err := http.NewRequest("GET", "/", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + spa := spaHandler{staticPath: "./build", indexPath: "index.html"} + spa.FilepathAbsServeHTTP(rr, req) + + status := rr.Code + if runtime.GOOS != "windows" && status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusOK) + } else if runtime.GOOS == "windows" && rr.Code != http.StatusInternalServerError { + t.Errorf("handler returned wrong status code in case of windows: got %v want %v", + status, http.StatusOK) + } + + // Check the response body is what we expect. + if runtime.GOOS != "windows" && rr.Body.String() != string(htmlContent) { + t.Errorf("handler returned unexpected body: got %v want %v", + rr.Body.String(), string(htmlContent)) + } else if runtime.GOOS == "windows" && strings.Contains(rr.Body.String(), "syntax is incorrect.") { + t.Errorf("handler returned unexpected body in case of windows: got %v want %v", + rr.Body.String(), string(htmlContent)) + } +} + +func TestServeHttpFilepathJoin(t *testing.T) { + // create a diretory name `build` + os.Mkdir("build", 0700) + + // create a file `index.html` and write below content + htmlContent := []byte(`helloworld`) + err := os.WriteFile("./build/index.html", htmlContent, 0700) + if err != nil { + t.Fatal(err) + } + + // make new request + req, err := http.NewRequest("GET", "/", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + spa := spaHandler{staticPath: "./build", indexPath: "index.html"} + spa.ServeHTTP(rr, req) + + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusOK) + } + + // Check the response body is what we expect. + if rr.Body.String() != string(htmlContent) { + t.Errorf("handler returned unexpected body: got %v want %v", + rr.Body.String(), string(htmlContent)) + } +} From eee21669a12a642e6ece7ba5f4172acc9f6dd44b Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Wed, 1 Jun 2022 23:23:31 +0530 Subject: [PATCH 16/21] fix comments wrap-lines and uncomment code --- mux_httpserver_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index 8faf75bd..95cccf3e 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -29,7 +29,10 @@ type spaHandler struct { // file located at the index path on the SPA handler will be served. This // is suitable behavior for serving an SPA (single page application). // This is a negative test case where `filepath.Abs` will return path value like `D:\` -// if our route is `/`. As per docs: Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result. +// if our route is `/`. As per docs: Abs returns an absolute representation of path. +// If the path is not absolute it will be joined with the current working directory to turn +// it into an absolute path. The absolute path name for a given file is not guaranteed to +// be unique. Abs calls Clean on the result. func (h spaHandler) FilepathAbsServeHTTP(w http.ResponseWriter, r *http.Request) { // get the absolute path to prevent directory traversal path, err := filepath.Abs(r.URL.Path) @@ -41,7 +44,7 @@ func (h spaHandler) FilepathAbsServeHTTP(w http.ResponseWriter, r *http.Request) } // prepend the path with the path to the static directory - // path = filepath.Join(h.staticPath, path) + path = filepath.Join(h.staticPath, path) // check whether a file exists at the given path _, err = os.Stat(path) @@ -66,8 +69,8 @@ func (h spaHandler) FilepathAbsServeHTTP(w http.ResponseWriter, r *http.Request) // file located at the index path on the SPA handler will be served. This // is suitable behavior for serving an SPA (single page application). func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - // get the absolute path to prevent directory traversal var err error + // internally calls path.Clean path to prevent directory traversal path := filepath.Join(h.staticPath, r.URL.Path) if err != nil { // if we failed to get the absolute path respond with a 400 bad request From 10803b51a58038f60234c37324052276a2e64716 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Wed, 1 Jun 2022 23:33:38 +0530 Subject: [PATCH 17/21] fix condition of response check of `TestServeHttpFilepathAbs` testcase --- mux_httpserver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index a219a80e..af7dd458 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -170,7 +170,7 @@ func TestServeHttpFilepathAbs(t *testing.T) { // {{{ if runtime.GOOS != "windows" && rr.Body.String() != string(htmlContent) { t.Errorf("handler returned unexpected body: got %v want %v", rr.Body.String(), string(htmlContent)) - } else if runtime.GOOS == "windows" && strings.Contains(rr.Body.String(), "syntax is incorrect.") { + } else if runtime.GOOS == "windows" && !strings.Contains(rr.Body.String(), "syntax is incorrect.") { t.Errorf("handler returned unexpected body in case of windows: got %v want %v", rr.Body.String(), string(htmlContent)) } From 77677fa98d802e4cccdc5c9521c8a00039adbe7e Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Mon, 20 Jun 2022 09:39:39 +0530 Subject: [PATCH 18/21] allow all branches and PR, run go >= 1.13 --- .github/workflows/pipeline.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 7363c95f..c69014fd 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -7,14 +7,9 @@ name: Continous Integration on: push: branches: - - master - - staging - - develop + - '*' pull_request: - branches: - - master - - staging - - develop + - '*' # Cancels all previous workflow runs for pull requests that have not completed. concurrency: @@ -42,7 +37,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v2 with: - go-version: '1.18.0' # The Go version to download (if necessary) and use. + go-version: '>=1.13' # The Go version to download (if necessary) and use. # Install all the dependencies - name: Install dependencies From 716948e2c665940b22e732f94281ba545772fd0c Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Mon, 20 Jun 2022 09:46:04 +0530 Subject: [PATCH 19/21] fix indentation and add tags to run pipeline --- .github/workflows/pipeline.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index c69014fd..2e94dbdd 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -7,9 +7,11 @@ name: Continous Integration on: push: branches: - - '*' - pull_request: - - '*' + - '*' + pull_request: + - '*' + tags: + - '*' # Cancels all previous workflow runs for pull requests that have not completed. concurrency: From e2cb73fcb2ec40d13e3a33e639903c9d50c5c53d Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Mon, 20 Jun 2022 09:51:45 +0530 Subject: [PATCH 20/21] add multiple golang versions --- .github/workflows/pipeline.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 2e94dbdd..8b77b49d 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -29,6 +29,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] + golang: ["latest", "1.17", "1.16"] # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -39,7 +40,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v2 with: - go-version: '>=1.13' # The Go version to download (if necessary) and use. + go-version: ${{matrix.golang}} # The Go version to download (if necessary) and use. # Install all the dependencies - name: Install dependencies From c6ffc0294a4f32ba46232184d8bb62cb2435a078 Mon Sep 17 00:00:00 2001 From: Mustaque Ahmed Date: Mon, 20 Jun 2022 09:58:50 +0530 Subject: [PATCH 21/21] replace `latest` version to `1.18` go version --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8b77b49d..7f3275b6 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - golang: ["latest", "1.17", "1.16"] + golang: ["1.18", "1.17", "1.16"] # Steps represent a sequence of tasks that will be executed as part of the job steps: