Skip to content

Commit

Permalink
Use stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
aburdulescu committed Apr 10, 2023
1 parent 669a7f8 commit 1573ccf
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 50 deletions.
14 changes: 1 addition & 13 deletions internal/ipc/ipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

const SocketAddr = "/tmp/baxs.sock"

//go:generate stringer -type=Op
type Op uint8

const (
Expand All @@ -18,19 +19,6 @@ const (
OpStart
)

func (op Op) String() string {
switch op {
case OpPs:
return "ps"
case OpStop:
return "stop"
case OpStart:
return "start"
default:
return "unknown"
}
}

type Request struct {
Stop *StopInput `json:",omitempty"`
Start *StartInput `json:",omitempty"`
Expand Down
19 changes: 0 additions & 19 deletions internal/ipc/ipc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,6 @@ func TestStart(t *testing.T) {
}
}

func TestOp(t *testing.T) {
tests := []struct {
name string
op Op
}{
{"ps", OpPs},
{"start", OpStart},
{"stop", OpStop},
{"unknown", Op(255)},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if v := test.op.String(); v != test.name {
t.Fatalf("expected %s, have %s", test.name, v)
}
})
}
}

func TestWire(t *testing.T) {
t.Run("EmptyRequest", func(t *testing.T) {
var r Request
Expand Down
25 changes: 25 additions & 0 deletions internal/ipc/op_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 1 addition & 17 deletions internal/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"bandr.me/p/baxs/internal/ipc"
)

//go:generate stringer -type=State
type State uint8

const (
Expand All @@ -23,23 +24,6 @@ const (
Finished
)

func (s State) String() string {
switch s {
case Idle:
return "idle"
case Failed:
return "failed"
case Running:
return "running"
case Stopped:
return "stopped"
case Finished:
return "finished"
default:
return fmt.Sprintf("invalid state: %d", s)
}
}

type Process struct {
Cmd *exec.Cmd
Name string
Expand Down
27 changes: 27 additions & 0 deletions internal/process/state_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ dev: clean build vet lint test

ci: clean build vet test

build:
generate:
go generate ./...

build: generate
CGO_ENABLED=0 go build

vet:
Expand Down Expand Up @@ -31,3 +34,6 @@ fuzz:
release: dev clean
CGO_ENABLED=0 go build -ldflags "-s -w"
strip -s baxs

misc:
go install golang.org/x/tools/cmd/stringer@latest

0 comments on commit 1573ccf

Please sign in to comment.