Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Aug 10, 2022
1 parent 8c7aa22 commit fabaa21
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ jobs:
go-version: '1.18'
check-latest: true
cache: true
- name: Build # no tests yet
run: go build -v -o /dev/null
- name: Build
run: go build -v -o /tmp/installer
- name: Test
run: go test -v ./...
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ curl https://i.jpillora.com/<query>! | bash
* `repo` Github repository belonging to `user` (**required**)
* `release` Github release name (defaults to the **latest** release)
* `!` When provided, downloads binary directly into `/usr/local/bin/` (defaults to working directory)
* `!!` Uses `sudo` to `mv` into `/usr/local/bin/`

**Query Params**

Expand Down
49 changes: 49 additions & 0 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package handler_test

import (
"net/http/httptest"
"os/exec"
"testing"

"github.com/jpillora/installer/handler"
)

func TestJPilloraServe(t *testing.T) {
h := &handler.Handler{}
r := httptest.NewRequest("GET", "/jpillora/serve", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Result().StatusCode != 200 {
t.Fatalf("failed to get jpillora/serve asset status")
}
t.Log(w.Body.String())
}

func TestMicro(t *testing.T) {
h := &handler.Handler{}
r := httptest.NewRequest("GET", "/micro", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Result().StatusCode != 200 {
t.Fatalf("failed to get micro asset status")
}
t.Log(w.Body.String())
}

func TestMicroInstall(t *testing.T) {
h := &handler.Handler{}
r := httptest.NewRequest("GET", "/micro?type=script", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Result().StatusCode != 200 {
t.Fatalf("failed to get micro asset status")
}
// pipe into bash
bash := exec.Command("bash")
bash.Stdin = w.Body
out, err := bash.CombinedOutput()
if err != nil {
t.Fatalf("failed to install micro: %s %s", err, out)
}
t.Log(string(out))
}
Binary file added handler/micro
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/install.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function install {
echo -n "{{ if .MoveToPath }}Installing{{ else }}Downloading{{ end }}"
echo -n " $USER/$PROG"
if [ ! -z "$RELEASE" ]; then
echo -n " <$RELEASE>"
echo -n " $RELEASE"
fi
echo -n " (${OS}/${ARCH})"
{{ if .Google }}
Expand Down

0 comments on commit fabaa21

Please sign in to comment.