41 lines
776 B
Go
41 lines
776 B
Go
// Copyright (c) 2023-2024 Onur Cinar.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
// https://github.com/cinar/checker
|
|
|
|
package v2_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
v2 "github.com/cinar/checker/v2"
|
|
)
|
|
|
|
func TestRequiredSuccess(t *testing.T) {
|
|
value := "test"
|
|
|
|
result, err := v2.Required(value)
|
|
|
|
if result != value {
|
|
t.Fatalf("result (%s) is not the original value (%s)", result, value)
|
|
}
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestRequiredMissing(t *testing.T) {
|
|
var value string
|
|
|
|
result, err := v2.Required(value)
|
|
|
|
if result != value {
|
|
t.Fatalf("result (%s) is not the original value (%s)", result, value)
|
|
}
|
|
|
|
if !errors.Is(err, v2.ErrRequired) {
|
|
t.Fatalf("got unexpected error %v", err)
|
|
}
|
|
}
|