Skip to content

Commit

Permalink
Run gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
SSushmitha8 committed Oct 17, 2024
1 parent 7b332bf commit 4bcadec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
6 changes: 2 additions & 4 deletions xtime/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (d *Duration) UnmarshalYAML(value *yaml.Node) error {
return nil
}
return fmt.Errorf("unable to unmarshal %s", value.Tag)

}

// UnmarshalJSON implements json.Unmarshaler
Expand Down Expand Up @@ -125,7 +124,6 @@ func (d Duration) Msgsize() int {
}

// Implements yaml.Marshaler - Converts duration to human-readable format (e.g., "2h", "30m")

Check failure on line 126 in xtime/time.go

View workflow job for this annotation

GitHub Actions / Test LDAP configuration validator (Go 1.22.x)

exported: comment on exported method Duration.MarshalYAML should be of the form "MarshalYAML ..." (revive)

Check failure on line 126 in xtime/time.go

View workflow job for this annotation

GitHub Actions / Build Go 1.22.x

exported: comment on exported method Duration.MarshalYAML should be of the form "MarshalYAML ..." (revive)
func (d Duration) MarshalYAML() (interface{}, error) {
return time.Duration(d).String(), nil
func (d Duration) MarshalYAML() (interface{}, error) {
return time.Duration(d).String(), nil
}

17 changes: 6 additions & 11 deletions xtime/time_unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ dur: 1w1s`)
if err := json.Unmarshal(jsonData, &jsonTest); err != nil {
t.Fatal(err)
}

}

func TestMarshalUnmarshalDuration(t *testing.T) {
Expand Down Expand Up @@ -113,32 +112,28 @@ func TestEncodeDecodeDuration(t *testing.T) {
}
}


func TestDuration_Marshal(t *testing.T) {
type testDuration struct {
A Duration `json:"a" yaml:"a"`
Dur Duration `json:"dur" yaml:"dur"`
A Duration `json:"a" yaml:"a"`
Dur Duration `json:"dur" yaml:"dur"`
DurationPointer *Duration `json:"durationPointer,omitempty" yaml:"durationPointer,omitempty"`
}


d1 := Duration(time.Second)
d2 := Duration(0)
d3 := Duration(time.Hour*24*7 + time.Second)
d2 := Duration(0)
d3 := Duration(time.Hour*24*7 + time.Second)

testData := testDuration{
A: d1,
Dur: d2,
A: d1,
Dur: d2,
DurationPointer: &d3,
}


yamlData, err := yaml.Marshal(&testData)
if err != nil {
t.Fatalf("Failed to marshal YAML: %v", err)
}


expected := `a: 1s
dur: 0s
durationPointer: 168h0m1s
Expand Down

0 comments on commit 4bcadec

Please sign in to comment.