add test for KontorTime
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
2026-10-04 23:05:53 +02:00
parent dea3c3d36a
commit e811fda863
4 changed files with 58 additions and 3 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ var exportCmd = &cobra.Command{
"user/mail": &mail,
}
for path, value := range registry {
GetJSON(client, login.Token, fmt.Sprintf("%s/%s/%s", server, "api/v1", path), value)
GetJSON(client, login.Token, fmt.Sprintf("%s/%s/%s", server, apiVersion, path), value)
}
export := ExportData{
Sport: sports,
+1 -1
View File
@@ -37,6 +37,6 @@ func Execute() {
}
func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/kli.yaml)")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "c", "config file (default is $HOME/.config/kli.yaml)")
rootCmd.PersistentFlags().CountVarP(&verbose, "verbose", "v", "increase verbosity (-v, -vv, -vvv)")
}
+2 -1
View File
@@ -39,7 +39,8 @@ type KontorTime struct {
var layouts = []string{
"2006-01-02 15:04:05.000000",
"2006-01-02T15:04:05.000000Z",
"2006-01-02T15:04:05.999Z",
"2006-01-02",
}
func (kt KontorTime) MarshalJSON() ([]byte, error) {
+54
View File
@@ -0,0 +1,54 @@
package helpers
import (
"encoding/json"
"testing"
)
func TestMultiFormatTimeUnmarshal(t *testing.T) {
tests := []struct {
name string
input string
wantErr bool
want string // Expected time string for comparison
}{
{
name: "Date Only",
input: `"2005-04-01"`,
wantErr: false,
want: "2005-04-01 00:00:00 +0000 UTC",
},
{
name: "KontorTime Format",
input: `"2026-04-30T13:54:26.334Z"`,
wantErr: false,
want: "2026-04-30 13:54:26.334 +0000 UTC",
},
{
name: "Null Value",
input: `null`,
wantErr: false,
want: "", // Zero time
},
{
name: "Invalid Format",
input: `"not-a-date"`,
wantErr: true,
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var m KontorTime
err := json.Unmarshal([]byte(tt.input), &m)
if (err != nil) != tt.wantErr {
t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && !m.Time.IsZero() && m.Time.String() != tt.want {
t.Errorf("UnmarshalJSON() = %v, want %v", m.Time.String(), tt.want)
}
})
}
}