Middle
How was the service tested? How was it deployed in Kubernetes?
sobes.tech AI
Answer from AI
For testing the service in Go, I usually use unit testing with the testing package. I write tests for key functions, covering different scenarios, including edge cases and errors. For integration testing, you can set up a test environment using Docker Compose or use mock services.
For deployment in Kubernetes, I create Deployment and Service manifests describing the container with the service, the number of replicas, resource settings, and ports. I use ConfigMap and Secret for configurations and secrets. Deployment is performed via kubectl apply -f or with Helm charts for more complex configurations.
Example of a simple Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-go-service
spec:
replicas: 3
selector:
matchLabels:
app: my-go-service
template:
metadata:
labels:
app: my-go-service
spec:
containers:
- name: my-go-service
image: myregistry/my-go-service:latest
ports:
- containerPort: 8080
Tests in Go:
func TestCalculate(t *testing.T) {
result := Calculate(2, 3)
if result != 5 {
t.Errorf("Expected 5, got %d", result)
}
}