Skip to content

Commit

Permalink
all: added basic tests
Browse files Browse the repository at this point in the history
Use testscript to test go-chromecast command helptext and the version.

Added _maybe_ working github action to test.
  • Loading branch information
vishen committed Oct 22, 2019
1 parent 5db2340 commit 3c39494
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.12'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@master
with:
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test

on: [push, pull_request]

jobs:
test:
strategy:
matrix:
go-version: [1.12.x]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Test
run: go test ./...
7 changes: 3 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package cmd

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -50,7 +49,7 @@ command line.`,

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(version, commit, date string) {
func Execute(version, commit, date string) int {
Version = version
Commit = commit
if date != "" {
Expand All @@ -59,9 +58,9 @@ func Execute(version, commit, date string) {
Date = time.Now().UTC().Format(time.RFC3339)
}
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
return 1
}
return 0
}

func init() {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d // indirect
github.com/pkg/errors v0.8.1
github.com/rogpeppe/go-internal v1.5.0
github.com/sirupsen/logrus v1.4.0
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
google.golang.org/api v0.3.0
google.golang.org/genproto v0.0.0-20190321212433-e79c0c59cdb5
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
Expand Down Expand Up @@ -113,6 +118,8 @@ github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/go-internal v1.5.0 h1:Usqs0/lDK/NqTkvrmKSwA/3XkZAs7ZAW/eLeQ2MVBTw=
github.com/rogpeppe/go-internal v1.5.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.0 h1:yKenngtzGh+cUSSh6GWbxW2abRqhYUSR/t/6+2QqNvE=
Expand Down Expand Up @@ -213,7 +220,10 @@ google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package main

import "github.com/vishen/go-chromecast/cmd"
import (
"os"

"github.com/vishen/go-chromecast/cmd"
)

var (
// These are build-time variables that get set by goreleaser.
Expand All @@ -24,5 +28,9 @@ var (
)

func main() {
cmd.Execute(version, commit, date)
os.Exit(main1())
}

func main1() int {
return cmd.Execute(version, commit, date)
}
20 changes: 20 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"os"
"testing"

"github.com/rogpeppe/go-internal/testscript"
)

func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"go-chromecast": main1,
}))
}

func TestCommands(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: "testdata",
})
}
7 changes: 7 additions & 0 deletions testdata/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# hello world
exec cat hello.text
stdout 'hello world\n'
! stderr .

-- hello.text --
hello world
47 changes: 47 additions & 0 deletions testdata/helptext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Check Helptext
go-chromecast
cmp stdout expected-helptext.txt
! stderr .


-- expected-helptext.txt --
Control your Google Chromecast or Google Home Mini from the
command line.

Usage:
go-chromecast [flags]
go-chromecast [command]

Available Commands:
help Help about any command
load Load and play media on the chromecast
ls List devices
next Play the next available media
pause Pause the currently playing media on the chromecast
playlist Load and play media on the chromecast
previous Play the previous available media
restart Restart the currently playing media
rewind Rewind by seconds the currently playing media
seek Seek by seconds into the currently playing media
status Current chromecast status
stop Stop casting
tts text-to-speech
ui Run the UI
unpause Unpause the currently playing media on the chromecast
volume Get or set volume
watch Watch all events sent from a chromecast device

Flags:
-a, --addr string Address of the chromecast device
-v, --debug debug logging
-d, --device string chromecast device, ie: 'Chromecast' or 'Google Home Mini'
-n, --device-name string chromecast device name
--disable-cache disable the cache
-h, --help help for go-chromecast
-i, --iface string Network interface to use when looking for a local address to use for the http server
-p, --port string Port of the chromecast device if 'addr' is specified (default "8009")
-u, --uuid string chromecast device uuid
--version display command version
--with-ui run with a UI

Use "go-chromecast [command] --help" for more information about a command.
4 changes: 4 additions & 0 deletions testdata/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Version
go-chromecast --version
stdout 'go-chromecast dev \(master\)'
! stderr .
5 changes: 0 additions & 5 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
CLI
---
* Control volume via command line; +10%, -10% or set a value between 0-99.
* Is it possible to support subtitles.

UI
--
* Get the application metadata to update from whatever the chosen chromecast is doing (not just the first thing it was doing)
Expand Down

0 comments on commit 3c39494

Please sign in to comment.