mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTimeStr(t *testing.T) {
|
|
t.Run("Parse", func(t *testing.T) {
|
|
// Test TimeEstimateParse
|
|
tests := []struct {
|
|
input string
|
|
output int64
|
|
err bool
|
|
}{
|
|
{"1h", 3600, false},
|
|
{"1m", 60, false},
|
|
{"1s", 1, false},
|
|
{"1h 1m 1s", 3600 + 60 + 1, false},
|
|
{"1d1x", 0, true},
|
|
{"1h 2x 3m", 0, true},
|
|
{"1h_2m", 0, true},
|
|
{"1h,1m", 0, true},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.input, func(t *testing.T) {
|
|
output, err := TimeEstimateParse(test.input)
|
|
if test.err {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
assert.Equal(t, test.output, output)
|
|
})
|
|
}
|
|
})
|
|
t.Run("String", func(t *testing.T) {
|
|
tests := []struct {
|
|
input int64
|
|
output string
|
|
}{
|
|
{3600, "1h"},
|
|
{60, "1m"},
|
|
{1, "1s"},
|
|
{3600 + 1, "1h 1s"},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.output, func(t *testing.T) {
|
|
output := TimeEstimateString(test.input)
|
|
assert.Equal(t, test.output, output)
|
|
})
|
|
}
|
|
})
|
|
}
|