Merged in feature/docinit (pull request #48)
Feature/docinit * createunittests * cleanup * skip * cleanup
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package validation_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/validation"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetUpdatedValue(t *testing.T) {
|
||||
assert.Equal(t, 1, validation.GetUpdatedValue(1, nil))
|
||||
val := 3
|
||||
assert.Equal(t, 3, validation.GetUpdatedValue(1, &val))
|
||||
|
||||
assert.Equal(t, "hello", validation.GetUpdatedValue("hello", nil))
|
||||
valstr := "byebye"
|
||||
assert.Equal(t, "byebye", validation.GetUpdatedValue("hello", &valstr))
|
||||
}
|
||||
|
||||
func TestDeduplicateArray(t *testing.T) {
|
||||
assert.ElementsMatch(t, []int{}, validation.DeduplicateArray([]int{}))
|
||||
assert.ElementsMatch(t, []int{1, 2, 3}, validation.DeduplicateArray([]int{1, 2, 3}))
|
||||
assert.ElementsMatch(t, []int{1, 2, 3}, validation.DeduplicateArray([]int{1, 2, 1, 3}))
|
||||
assert.ElementsMatch(t, []int{1}, validation.DeduplicateArray([]int{1, 1, 1, 1}))
|
||||
id := uuid.New()
|
||||
assert.ElementsMatch(t, []uuid.UUID{id}, validation.DeduplicateArray([]uuid.UUID{id, id, id}))
|
||||
}
|
||||
|
||||
func TestNormalizeInClosedInterval(t *testing.T) {
|
||||
err := validation.NormalizeInClosedInterval(nil, 1, 1, 1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var param *int32
|
||||
err = validation.NormalizeInClosedInterval(¶m, 1, 1, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, param)
|
||||
|
||||
updated := int32(1)
|
||||
param = &updated
|
||||
err = validation.NormalizeInClosedInterval(¶m, 1, 1, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int32(1), updated)
|
||||
|
||||
updated = -1
|
||||
param = &updated
|
||||
err = validation.NormalizeInClosedInterval(¶m, 1, 1, 1)
|
||||
assert.Error(t, err)
|
||||
|
||||
updated = 2
|
||||
param = &updated
|
||||
err = validation.NormalizeInClosedInterval(¶m, 1, 1, 1)
|
||||
assert.Error(t, err)
|
||||
|
||||
updated = 2
|
||||
param = &updated
|
||||
err = validation.NormalizeInClosedInterval(¶m, 1, 1, 3)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int32(2), updated)
|
||||
}
|
||||
Reference in New Issue
Block a user