From bd4f0ba092efe2de84f2104eb50d75fbe3b9b88f Mon Sep 17 00:00:00 2001 From: James Walker Date: Thu, 30 Jun 2022 18:08:27 -0400 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=9A=20add=20drone=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..67231d4 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,11 @@ +--- +kind: pipeline +type: docker +name: NixOS Packages + +steps: + - name: Build + image: nixpkgs/cachix-flakes:nixos-22.05 + commands: + - nix flake check .# + - nix build .# -- 2.47.0 From b0e5696ba99d268fcd7fd847ad69aa6611a7feab Mon Sep 17 00:00:00 2001 From: James Walker Date: Thu, 30 Jun 2022 19:57:14 -0400 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=B7=20go=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 67231d4..ac03f27 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,11 +1,11 @@ --- kind: pipeline type: docker -name: NixOS Packages +name: default steps: - - name: Build - image: nixpkgs/cachix-flakes:nixos-22.05 + - name: tests + image: golang:1.17 commands: - - nix flake check .# - - nix build .# + - go build -v + - go test -v ./... -- 2.47.0 From 34e25bfd2822d22f00c5e89b8a75617a96c75235 Mon Sep 17 00:00:00 2001 From: James Walker Date: Thu, 4 Aug 2022 17:38:28 -0400 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20add=20an=20actual=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 1 + tmux/project.go | 5 ++++- tmux/tmux.go | 34 ++++++++++++++++++++++------------ tmux/tmux_test.go | 12 ++++++++++++ 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 tmux/tmux_test.go diff --git a/.drone.yml b/.drone.yml index ac03f27..77ea9f6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,5 +7,6 @@ steps: - name: tests image: golang:1.17 commands: + - apt-get update && apt-get install -y tmux - go build -v - go test -v ./... diff --git a/tmux/project.go b/tmux/project.go index 5b80fa7..3e2b916 100644 --- a/tmux/project.go +++ b/tmux/project.go @@ -227,7 +227,10 @@ func getConfigFilePath(name string) string { func sessionExists(name string) bool { t := Tmux{} - sessions := t.ListSessions() + sessions, err := t.ListSessions() + if err != nil { + return false + } for _, s := range sessions { if s == name { return true diff --git a/tmux/tmux.go b/tmux/tmux.go index 9e0eda0..ea63ac8 100644 --- a/tmux/tmux.go +++ b/tmux/tmux.go @@ -1,6 +1,7 @@ package tmux import ( + "errors" "fmt" "os" "os/exec" @@ -18,7 +19,10 @@ func CreateTmux(debug bool) *Tmux { } func (t *Tmux) Exec(args ...string) ([]byte, error) { - bin := t.getBinary() + bin, err := t.getBinary() + if err != nil { + return []byte{}, err + } if t.Debug { fmt.Println(bin, strings.Join(args, " ")) } @@ -32,26 +36,32 @@ func (t *Tmux) Run(args ...string) { } } -func (t *Tmux) Attach(name string) { +func (t *Tmux) Attach(name string) error { args := []string{} args = append(args, "-u", "attach-session", "-t", name) - err := syscall.Exec(t.getBinary(), args, os.Environ()) + bin, err := t.getBinary() if err != nil { - fmt.Println("Error:", err) + return err } + err = syscall.Exec(bin, args, os.Environ()) + if err != nil { + return err + } + return nil } -func (t *Tmux) ListSessions() []string { +func (t *Tmux) ListSessions() ([]string, error) { sessions := []string{} result, err := t.Exec("ls", "-F", "#{session_name}") - if err != nil { + if errors.Is(err, exec.ErrNotFound) { // No active sessions returns as an error. - return sessions + return sessions, err } lines := strings.Trim(string(result), "\n") - return strings.Split(lines, "\n") + fmt.Println("Sessions", lines) + return strings.Split(lines, "\n"), nil } func (t *Tmux) KillSession(name string) error { @@ -59,15 +69,15 @@ func (t *Tmux) KillSession(name string) error { return err } -func (t *Tmux) getBinary() string { +func (t *Tmux) getBinary() (string, error) { if t.BinPath != "" { - return t.BinPath + return t.BinPath, nil } tmux, err := exec.LookPath("tmux") if err != nil { - fmt.Println("Error:", err) + return "", err } - return tmux + return tmux, nil } diff --git a/tmux/tmux_test.go b/tmux/tmux_test.go new file mode 100644 index 0000000..7522832 --- /dev/null +++ b/tmux/tmux_test.go @@ -0,0 +1,12 @@ +package tmux + +import ( + "testing" +) + +func TestListSessions(t *testing.T) { + m := CreateTmux(true) + if _, err := m.ListSessions(); err != nil { + t.Fatalf("ListSessions: %s", err) + } +} -- 2.47.0