chore: initialize containerized Go learning workbook (2026 DevOps/SRE)
This commit is contained in:
commit
84be3e5d77
64 files changed
+1382
No files matched your search
@@ -0,0 +1,10 @@
|
||||
# 03 — Programowanie Cross-Platform (`path/filepath`, env vars, `runtime.GOOS`)
|
||||
|
||||
## Zadania (`crossos.go`)
|
||||
1. `ConfigPath(baseDir, appName string) string` — użyj `filepath.Join(baseDir, appName, "config.yaml")`.
|
||||
2. `EnvOrDefault(lookup func(string) (string, bool), key, fallback string) string` — pobierz zmienną ze wstrzykniętej funkcji `lookup` (np. `os.LookupEnv`) lub zwróć `fallback` gdy brak lub pusta.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test PKG=./exercises/02-engineering-2026/03-cross-platform-os
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
package crossos
|
||||
|
||||
func ConfigPath(baseDir, appName string) string {
|
||||
panic("TODO: użyj filepath.Join(baseDir, appName, \"config.yaml\")")
|
||||
}
|
||||
|
||||
func EnvOrDefault(lookup func(string) (string, bool), key, fallback string) string {
|
||||
panic("TODO: wywołaj lookup(key); jeśli brak lub puste po TrimSpace -> fallback")
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package crossos
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfigPath(t *testing.T) {
|
||||
base := filepath.Join("home", "ops")
|
||||
got := ConfigPath(base, "monitor")
|
||||
want := filepath.Join(base, "monitor", "config.yaml")
|
||||
if got != want {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvOrDefault(t *testing.T) {
|
||||
env := map[string]string{"LOG_LEVEL": "debug", "EMPTY": " "}
|
||||
lookup := func(k string) (string, bool) { v, ok := env[k]; return v, ok }
|
||||
|
||||
if got := EnvOrDefault(lookup, "LOG_LEVEL", "info"); got != "debug" {
|
||||
t.Fatalf("got %q, want debug", got)
|
||||
}
|
||||
if got := EnvOrDefault(lookup, "EMPTY", "info"); got != "info" {
|
||||
t.Fatalf("got %q, want info", got)
|
||||
}
|
||||
if got := EnvOrDefault(lookup, "MISSING", "info"); got != "info" {
|
||||
t.Fatalf("got %q, want info", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user