Enforce Go code style for ollama-machine project - table-driven tests with gomega assertions and proper godoc formatting.
Enforce Go coding conventions for the ollama-machine project (alexandrevilain/ollama-machine) - a docker-machine-like tool for managing GPU cloud instances running Ollama.
This skill ensures consistent code style across the ollama-machine codebase, with emphasis on:
When writing or reviewing Go code for ollama-machine, follow these conventions:
**All godoc comments must end with a period (full stop).**
```go
// Good
// NewMachine creates a new machine instance on the specified cloud provider.
func NewMachine(provider string) (*Machine, error) { ... }
// Bad
// NewMachine creates a new machine instance on the specified cloud provider
func NewMachine(provider string) (*Machine, error) { ... }
```
Apply this rule to:
**Always use map-based table-driven tests with the following pattern:**
```go
func TestFunctionName(t *testing.T) {
tests := map[string]struct {
// Input fields
input string
config Config
// Expected output fields
result string
err error
}{
"descriptive test case name": {
input: "test value",
result: "expected output",
},
"edge case - empty input": {
input: "",
result: "",
},
"error case - invalid config": {
input: "bad",
err: ErrInvalidConfig,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
result, err := FunctionName(test.input)
if test.err != nil {
g.Expect(err).To(MatchError(test.err))
} else {
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result).To(Equal(test.result))
}
})
}
}
```
**Import gomega using dot import:**
```go
import (
"testing"
. "github.com/onsi/gomega"
)
```
**Common gomega matchers for ollama-machine:**
```go
// Equality checks
g.Expect(machine.Status).To(Equal("running"))
// Error handling
g.Expect(err).ToNot(HaveOccurred())
g.Expect(err).To(MatchError(ErrCredentialsNotFound))
// Collection checks
g.Expect(machines).To(HaveLen(3))
g.Expect(providers).To(ContainElement("aws"))
// Pointer checks
g.Expect(config).ToNot(BeNil())
// String checks
g.Expect(output).To(ContainSubstring("Ollama is running"))
```
Structure test files to match the ollama-machine architecture:
```go
// For provider-specific code
func TestProviderOperation(t *testing.T) {
tests := map[string]struct {
provider string
credentials Credentials
expectError bool
}{
"AWS with valid credentials": {
provider: "aws",
credentials: Credentials{
AccessKey: "AKIA...",
SecretKey: "secret",
},
expectError: false,
},
"invalid provider": {
provider: "unknown",
expectError: true,
},
}
// ... test implementation
}
```
When testing credential storage and cloud operations:
```go
tests := map[string]struct {
credentials Credentials
encrypted bool
expectPanic bool
}{
"encrypted credentials storage": {
credentials: Credentials{APIKey: "secret"},
encrypted: true,
expectPanic: false,
},
"plaintext credentials rejected": {
credentials: Credentials{APIKey: "secret"},
encrypted: false,
expectPanic: true,
},
}
```
Use descriptive names that explain the scenario:
```go
tests := map[string]struct {
// ...
}{
"successful machine creation on AWS": {...},
"error when GPU not available": {...},
"timeout during ollama installation": {...},
"credentials loaded from secure keyring": {...},
"multi-byte characters in machine name": {...},
}
```
```go
package machine
import (
"testing"
. "github.com/onsi/gomega"
)
// ReverseName reverses a machine name for display purposes.
func TestReverseName(t *testing.T) {
tests := map[string]struct {
input string
result string
}{
"empty string": {
input: "",
result: "",
},
"single character": {
input: "x",
result: "x",
},
"multi-byte emoji": {
input: "π",
result: "π",
},
"multiple emojis": {
input: "π₯³ππΆ",
result: "πΆππ₯³",
},
"machine name": {
input: "ollama-gpu-1",
result: "1-upg-amallo",
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
result := ReverseName(test.input)
g.Expect(result).To(Equal(test.result))
})
}
}
```
1. **Always end godoc sentences with a period**
2. **Use map-based table-driven tests** (not slice-based)
3. **Import gomega with dot notation** (`. "github.com/onsi/gomega"`)
4. **Run subtests in parallel** (`t.Parallel()`)
5. **Use descriptive test case names** that explain the scenario
6. **Test security-sensitive operations** (credentials, encryption, cloud API calls)
This skill is specific to the ollama-machine project, which manages GPU cloud instances for running Ollama. When writing tests for cloud provider integrations, credential storage, or machine lifecycle operations, prioritize:
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/ollama-machine-go-conventions/raw