Compare commits
4 commits
main
...
issue-6-ma
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b16de316e4 | ||
|
|
37083dd4c1 | ||
|
|
452ef5f1fa | ||
|
|
938b08c734 |
11 changed files with 126 additions and 36 deletions
17
.gitignore
vendored
17
.gitignore
vendored
|
|
@ -4,24 +4,25 @@
|
||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
test
|
||||||
|
test.exe
|
||||||
|
test.test
|
||||||
|
|
||||||
# Test binary
|
# Test binary
|
||||||
*.test
|
*.test
|
||||||
|
|
||||||
# Output of the go coverage tool
|
# Output of the go coverage
|
||||||
*.out
|
profile.out
|
||||||
|
|
||||||
# Dependency directories
|
# Go build directory
|
||||||
vendor/
|
vendor/
|
||||||
|
|
||||||
# Go build cache
|
# Binary directory
|
||||||
$(GOPATH)/pkg/
|
bin/
|
||||||
|
|
||||||
# Build artifacts
|
|
||||||
build/
|
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
*~
|
||||||
|
|
|
||||||
17
Makefile
17
Makefile
|
|
@ -1,17 +0,0 @@
|
||||||
.PHONY: build run test clean
|
|
||||||
|
|
||||||
APP_NAME := testbed2
|
|
||||||
BUILD_DIR := build
|
|
||||||
|
|
||||||
build:
|
|
||||||
go build -o $(BUILD_DIR)/$(APP_NAME) .
|
|
||||||
|
|
||||||
run: build
|
|
||||||
./$(BUILD_DIR)/$(APP_NAME)
|
|
||||||
|
|
||||||
test:
|
|
||||||
go test ./...
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf $(BUILD_DIR)
|
|
||||||
go clean -cache
|
|
||||||
15
cmd/cli/main.go
Normal file
15
cmd/cli/main.go
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/marmaduke/testbed2/pkg/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if err := cli.Run(os.Args[1:]); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
15
cmd/testbed2/main.go
Normal file
15
cmd/testbed2/main.go
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/marmaduke/testbed2/pkg/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if err := cli.Run(os.Args[1:]); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,3 +1,3 @@
|
||||||
module github.com/marmaduke/testbed2
|
module github.com/marmaduke/testbed2
|
||||||
|
|
||||||
go 1.24
|
go 1.21
|
||||||
|
|
|
||||||
3
main.go
3
main.go
|
|
@ -1,3 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
func main() {}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestModule(t *testing.T) {
|
|
||||||
// Basic test to verify module initialization
|
|
||||||
}
|
|
||||||
25
pkg/cli/cli.go
Normal file
25
pkg/cli/cli.go
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Package cli provides the core CLI functionality.
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Run executes the CLI with the given arguments.
|
||||||
|
func Run(args []string) error {
|
||||||
|
if len(args) == 0 {
|
||||||
|
fmt.Println("testbed2 CLI")
|
||||||
|
fmt.Println("Usage: testbed2 <command>")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch args[0] {
|
||||||
|
case "help", "--help", "-h":
|
||||||
|
fmt.Println("Available commands:")
|
||||||
|
fmt.Println(" help Show this help message")
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown command: %s", args[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
61
pkg/cli/cli_test.go
Normal file
61
pkg/cli/cli_test.go
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRunNoArgs(t *testing.T) {
|
||||||
|
oldStdout := os.Stdout
|
||||||
|
_, w, _ := os.Pipe()
|
||||||
|
os.Stdout = w
|
||||||
|
|
||||||
|
err := Run([]string{})
|
||||||
|
|
||||||
|
w.Close()
|
||||||
|
os.Stdout = oldStdout
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunHelp(t *testing.T) {
|
||||||
|
oldStdout := os.Stdout
|
||||||
|
_, w, _ := os.Pipe()
|
||||||
|
os.Stdout = w
|
||||||
|
|
||||||
|
err := Run([]string{"help"})
|
||||||
|
|
||||||
|
w.Close()
|
||||||
|
os.Stdout = oldStdout
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunUnknownCommand(t *testing.T) {
|
||||||
|
err := Run([]string{"unknown"})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error for unknown command")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunOutput(t *testing.T) {
|
||||||
|
oldStdout := os.Stdout
|
||||||
|
r, w, _ := os.Pipe()
|
||||||
|
os.Stdout = w
|
||||||
|
|
||||||
|
_ = Run([]string{})
|
||||||
|
|
||||||
|
w.Close()
|
||||||
|
os.Stdout = oldStdout
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
_, _ = buf.ReadFrom(r)
|
||||||
|
if buf.Len() == 0 {
|
||||||
|
t.Fatal("expected output")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue