mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
refactor: manually modernize Go (#349)
Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -242,8 +242,8 @@ func (c *Controller) writeCaddyfileIfChanged(caddyfile string) error {
|
|||||||
// caddyfileBody returns the Caddyfile content without its first line, which carries a generation timestamp that
|
// caddyfileBody returns the Caddyfile content without its first line, which carries a generation timestamp that
|
||||||
// rotates on every regeneration.
|
// rotates on every regeneration.
|
||||||
func caddyfileBody(caddyfile string) string {
|
func caddyfileBody(caddyfile string) string {
|
||||||
if i := strings.IndexByte(caddyfile, '\n'); i >= 0 {
|
if _, after, ok := strings.Cut(caddyfile, "\n"); ok {
|
||||||
return caddyfile[i+1:]
|
return after
|
||||||
}
|
}
|
||||||
return caddyfile
|
return caddyfile
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ func TestContainerFingerprint_EqualCoversAllFields(t *testing.T) {
|
|||||||
assert.True(t, base.Equal(base), "base fingerprint must be equal to itself")
|
assert.True(t, base.Equal(base), "base fingerprint must be equal to itself")
|
||||||
|
|
||||||
rt := reflect.TypeOf(base)
|
rt := reflect.TypeOf(base)
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for field := range rt.Fields() {
|
||||||
field := rt.Field(i)
|
|
||||||
t.Run(field.Name, func(t *testing.T) {
|
t.Run(field.Name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ type MockCaddyfileValidator_Validate_Call struct {
|
|||||||
// Validate is a helper method to define mock.On call
|
// Validate is a helper method to define mock.On call
|
||||||
// - ctx context.Context
|
// - ctx context.Context
|
||||||
// - caddyfile string
|
// - caddyfile string
|
||||||
func (_e *MockCaddyfileValidator_Expecter) Validate(ctx interface{}, caddyfile interface{}) *MockCaddyfileValidator_Validate_Call {
|
func (_e *MockCaddyfileValidator_Expecter) Validate(ctx any, caddyfile any) *MockCaddyfileValidator_Validate_Call {
|
||||||
return &MockCaddyfileValidator_Validate_Call{Call: _e.mock.On("Validate", ctx, caddyfile)}
|
return &MockCaddyfileValidator_Validate_Call{Call: _e.mock.On("Validate", ctx, caddyfile)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -683,9 +683,7 @@ func (s *Server) CreateServiceContainer(
|
|||||||
// Apply the pre-deploy hook overrides.
|
// Apply the pre-deploy hook overrides.
|
||||||
config.Cmd = spec.PreDeploy.Command
|
config.Cmd = spec.PreDeploy.Command
|
||||||
|
|
||||||
for k, v := range spec.PreDeploy.Env {
|
maps.Copy(envVars, spec.PreDeploy.Env)
|
||||||
envVars[k] = v
|
|
||||||
}
|
|
||||||
envVars["UNCLOUD_HOOK_PRE_DEPLOY"] = "true"
|
envVars["UNCLOUD_HOOK_PRE_DEPLOY"] = "true"
|
||||||
config.Env = envVars.ToSlice()
|
config.Env = envVars.ToSlice()
|
||||||
|
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ func TestLogMerger_ZeroTimestampForwarding(t *testing.T) {
|
|||||||
merger := NewLogMerger([]<-chan api.ServiceLogEntry{ch}, LogMergerOptions{})
|
merger := NewLogMerger([]<-chan api.ServiceLogEntry{ch}, LogMergerOptions{})
|
||||||
output := merger.Stream()
|
output := merger.Stream()
|
||||||
|
|
||||||
for i := 0; i < zeroCount; i++ {
|
for range zeroCount {
|
||||||
ch <- testEntry(api.LogStreamStdout, time.Time{}, "zero")
|
ch <- testEntry(api.LogStreamStdout, time.Time{}, "zero")
|
||||||
}
|
}
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
@@ -237,7 +237,7 @@ func TestLogMerger_ZeroTimestampForwarding(t *testing.T) {
|
|||||||
results := collectEntries(t, output, 0)
|
results := collectEntries(t, output, 0)
|
||||||
require.Len(t, results, zeroCount+1)
|
require.Len(t, results, zeroCount+1)
|
||||||
|
|
||||||
for i := 0; i < zeroCount; i++ {
|
for i := range zeroCount {
|
||||||
assert.True(t, results[i].Timestamp.IsZero(), "entry %d should have zero timestamp", i)
|
assert.True(t, results[i].Timestamp.IsZero(), "entry %d should have zero timestamp", i)
|
||||||
assert.Equal(t, "zero", string(results[i].Message))
|
assert.Equal(t, "zero", string(results[i].Message))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user