Skip to content

Commit

Permalink
[YUNIKORN-2670] Improve util funtion's test coverage (#888)
Browse files Browse the repository at this point in the history
Closes: #888

Signed-off-by: Peter Bacsko <pbacsko@cloudera.com>
  • Loading branch information
SP12893678 authored and pbacsko committed Jun 11, 2024
1 parent d46f216 commit 070a678
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (

"gotest.tools/v3/assert"

"github.com/google/uuid"

"github.com/apache/yunikorn-scheduler-interface/lib/go/common"
"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
)
Expand Down Expand Up @@ -380,3 +382,35 @@ func TestGetConfigurationInt(t *testing.T) {
})
}
}

func TestZeroTimeInUnixNano(t *testing.T) {
// zero time
var nilValue *int64 = nil
assert.Equal(t, ZeroTimeInUnixNano(time.Time{}), nilValue)

// non-zero time
date := time.Date(2024, time.June, 6, 0, 0, 0, 0, time.UTC)
assert.Equal(t, *ZeroTimeInUnixNano(date), date.UnixNano())

// time in different timezone
date = time.Date(2024, time.June, 6, 0, 0, 0, 0, time.FixedZone("UTC+8", 8*60*60))
assert.Equal(t, *ZeroTimeInUnixNano(date), date.UnixNano())
}

func TestGetNewUUID(t *testing.T) {
newUUID := GetNewUUID()
if _, err := uuid.Parse(newUUID); err != nil {
t.Errorf("Generated UUID is not valid: %s", newUUID)
}
}

func TestIsRecoveryQueue(t *testing.T) {
// valid case
assert.Assert(t, IsRecoveryQueue("root.@recovery@"))
assert.Assert(t, IsRecoveryQueue("ROOT.@RECOVERY@"))
assert.Assert(t, IsRecoveryQueue("RoOT.@rECoVeRY@"))

// invalid case
assert.Assert(t, !IsRecoveryQueue("otherQueue"))
assert.Assert(t, !IsRecoveryQueue(""))
}

0 comments on commit 070a678

Please sign in to comment.