Repository: go-playground/validator
File: validator_test.go (Go)

Code before:
	if err := os.Mkdir(dirPath, 0755); err != nil && !os.IsExist(err) {
		t.Fatalf("Failed to create directory: %v", err)
	}
	defer func() {
		_ = os.RemoveAll(dirPath)
	}()
	errs = validate.Var(dirPath, "uds_exists")
	NotEqual(t, errs, nil)
	AssertError(t, errs, "", "", "", "", "uds_exists")

	if runtime.GOOS == "linux" {
		abstractSockName := "@test_abstract_socket_" + fmt.Sprintf("%d", time.Now().UnixNano())
		var lc net.ListenConfig
		abstractListener, err := lc.Listen(t.Context(), "unix", "\x00"+abstractSockName[1:])
		if err != nil {
			t.Fatalf("Failed to create abstract socket: %v", err)
		}
		defer func() {
			_ = abstractListener.Close()
		}()
		errs = validate.Var(abstractSockName, "uds_exists")
		Equal(t, errs, nil)
		errs = validate.Var("@nonexistent_abstract_socket", "uds_exists")
		NotEqual(t, errs, nil)
		AssertError(t, errs, "", "", "", "", "uds_exists")
	}
}

func TestSliceMapArrayChanFuncPtrInterfaceRequiredValidation(t *testing.T) {
	validate := New()

	var m map[string]string

	errs := validate.Var(m, "required")
	NotEqual(t, errs, nil)
	AssertError(t, errs, "", "", "", "", "required")

	m = map[string]string{}
	errs = validate.Var(m, "required")
	Equal(t, errs, nil)

	var arr [5]string
	errs = validate.Var(arr, "required")
	NotEqual(t, errs, nil)
	AssertError(t, errs, "", "", "", "", "required")

	arr[0] = "ok"
	errs = validate.Var(arr, "required")
	Equal(t, errs, nil)

	var s []string

Review comment (suggestion):
Only issue I have here, is that I would want the tests to be split up and ran as sub tests.

```go
t.Run("non_existant", func(t *testing.T) {
	errs = validate.Var("/tmp/nonexistent.sock", "uds_exists")
	NotEqual(t, errs, nil)
	AssertError(t, errs, "", "", "", "", "uds_exists")
})
```

Otherwise with all the `defer` and other things feel hard to read. 

Code after:
	}

	validate := New()

	for i, test := range tests {
		errs := validate.Var(test.param, "unix_addr")
		if test.expected {
			if !IsEqual(errs, nil) {
				t.Fatalf("Index: %d unix_addr failed Error: %s", i, errs)
			}
		} else {
			if IsEqual(errs, nil) {
				t.Log(test.param, IsEqual(errs, nil))
				t.Fatalf("Index: %d unix_addr failed Error: %s", i, errs)
			} else {
				val := getError(errs, "", "")
				if val.Tag() != "unix_addr" {
					t.Fatalf("Index: %d unix_addr failed Error: %s", i, errs)
				}
			}
		}
	}
}

func TestUnixDomainSocketExistsValidation(t *testing.T) {
	if runtime.GOOS == "windows" {
		t.Skip("Unix domain sockets are not supported on Windows")
	}

	validate := New()

	t.Run("empty", func(t *testing.T) {
		errs := validate.Var("", "uds_exists")
		NotEqual(t, errs, nil)
		AssertError(t, errs, "", "", "", "", "uds_exists")
	})

	t.Run("non_existent", func(t *testing.T) {
		errs := validate.Var("/tmp/nonexistent.sock", "uds_exists")
		NotEqual(t, errs, nil)
		AssertError(t, errs, "", "", "", "", "uds_exists")
	})

	t.Run("sock_file", func(t *testing.T) {
		sockPath := "/tmp/test_validator.sock"
		var lc net.ListenConfig
		listener, err := lc.Listen(t.Context(), "unix", sockPath)
		if err != nil {
			t.Fatalf("Failed to create test socket: %v", err)
		}
		defer func() {