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,39 @@
|
||||
package testing_ex
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type fakeStore map[string]string
|
||||
|
||||
func (f fakeStore) Get(key string) (string, bool) { v, ok := f[key]; return v, ok }
|
||||
|
||||
func TestFeatureFlagsTableDriven(t *testing.T) {
|
||||
flags := FeatureFlags{Store: fakeStore{"a": "true", "b": "1", "c": "false"}}
|
||||
cases := []struct {
|
||||
name string
|
||||
want bool
|
||||
}{{"a", true}, {"b", true}, {"c", false}, {"missing", false}}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := flags.IsEnabled(tc.name); got != tc.want {
|
||||
t.Errorf("IsEnabled(%q) = %v, want %v", tc.name, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteAndReadLines(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "lines.txt")
|
||||
want := []string{"alpha", "beta", "gamma"}
|
||||
got, err := WriteAndReadLines(path, want)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user