Skip to content

Commit 3f22eba

Browse files
committed
feat: add example command and tests
1 parent 8e79fb8 commit 3f22eba

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

cmd/go-cli-github/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var (
1515
// CLI represents the command-line interface.
1616
type CLI struct {
1717
Version VersionCmd `kong:"cmd,help='Print version information'"`
18+
Serve ServeCmd `kong:"cmd,help='Example serve command'"`
1819
}
1920

2021
func main() {

cmd/go-cli-github/serve.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/smlx/go-cli-github/internal/server"
7+
)
8+
9+
// ServeCmd represents the `serve` command.
10+
type ServeCmd struct{}
11+
12+
// Run the serve command.
13+
func (*ServeCmd) Run() error {
14+
fmt.Println(server.Serve())
15+
return nil
16+
}

internal/server/serve.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package server
2+
3+
// Serve is an example function.
4+
func Serve() string {
5+
return "example serve command"
6+
}

internal/server/serve_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package server_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/smlx/go-cli-github/internal/server"
7+
)
8+
9+
func TestServe(t *testing.T) {
10+
var testCases = map[string]struct {
11+
input string
12+
expect string
13+
}{
14+
"test Serve": {input: "", expect: "example serve command"},
15+
}
16+
for name, tc := range testCases {
17+
t.Run(name, func(tt *testing.T) {
18+
result := server.Serve()
19+
if result != tc.expect {
20+
tt.Fatalf("expected %s, got %s", tc.expect, result)
21+
}
22+
})
23+
}
24+
}

0 commit comments

Comments
 (0)