Compare commits

..

4 commits

11 changed files with 126 additions and 36 deletions

17
.gitignore vendored
View file

@ -4,24 +4,25 @@
*.dll
*.so
*.dylib
test
test.exe
test.test
# Test binary
*.test
# Output of the go coverage tool
*.out
# Output of the go coverage
profile.out
# Dependency directories
# Go build directory
vendor/
# Go build cache
$(GOPATH)/pkg/
# Build artifacts
build/
# Binary directory
bin/
# IDE
.idea/
.vscode/
*.swp
*.swo
*~

View file

@ -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
View 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)
}
}

View file

15
cmd/testbed2/main.go Normal file
View 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
View file

@ -1,3 +1,3 @@
module github.com/marmaduke/testbed2
go 1.24
go 1.21

View file

View file

@ -1,3 +0,0 @@
package main
func main() {}

View file

@ -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
View 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
View 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")
}
}