mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	
		
			Some checks failed
		
		
	
	Tests / test (./cmd/caddy/caddy, ~1.24.1, ubuntu-latest, 0, 1.24, linux) (push) Failing after 2m0s
				
			Tests / test (s390x on IBM Z) (push) Has been skipped
				
			Tests / goreleaser-check (push) Has been skipped
				
			Cross-Build / build (~1.24.1, 1.24, aix) (push) Successful in 1m20s
				
			Cross-Build / build (~1.24.1, 1.24, darwin) (push) Successful in 1m17s
				
			Cross-Build / build (~1.24.1, 1.24, dragonfly) (push) Successful in 1m18s
				
			Cross-Build / build (~1.24.1, 1.24, freebsd) (push) Successful in 1m14s
				
			Cross-Build / build (~1.24.1, 1.24, illumos) (push) Successful in 1m15s
				
			Cross-Build / build (~1.24.1, 1.24, linux) (push) Successful in 1m15s
				
			Cross-Build / build (~1.24.1, 1.24, netbsd) (push) Successful in 1m18s
				
			Cross-Build / build (~1.24.1, 1.24, openbsd) (push) Successful in 1m17s
				
			Cross-Build / build (~1.24.1, 1.24, solaris) (push) Successful in 1m18s
				
			Cross-Build / build (~1.24.1, 1.24, windows) (push) Successful in 1m15s
				
			Lint / lint (ubuntu-latest, linux) (push) Successful in 1m50s
				
			Lint / govulncheck (push) Successful in 1m19s
				
			Lint / lint (macos-14, mac) (push) Has been cancelled
				
			Lint / lint (windows-latest, windows) (push) Has been cancelled
				
			Tests / test (./cmd/caddy/caddy, ~1.24.1, macos-14, 0, 1.24, mac) (push) Has been cancelled
				
			Tests / test (./cmd/caddy/caddy.exe, ~1.24.1, windows-latest, True, 1.24, windows) (push) Has been cancelled
				
			* fix: crash - null check on event origin * chore: use accessor instead of property
		
			
				
	
	
		
			94 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2015 Matthew Holt and The Caddy Authors
 | |
| //
 | |
| // Licensed under the Apache License, Version 2.0 (the "License");
 | |
| // you may not use this file except in compliance with the License.
 | |
| // You may obtain a copy of the License at
 | |
| //
 | |
| //     http://www.apache.org/licenses/LICENSE-2.0
 | |
| //
 | |
| // Unless required by applicable law or agreed to in writing, software
 | |
| // distributed under the License is distributed on an "AS IS" BASIS,
 | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| // See the License for the specific language governing permissions and
 | |
| // limitations under the License.
 | |
| 
 | |
| package caddy
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"testing"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| func TestParseDuration(t *testing.T) {
 | |
| 	const day = 24 * time.Hour
 | |
| 	for i, tc := range []struct {
 | |
| 		input  string
 | |
| 		expect time.Duration
 | |
| 	}{
 | |
| 		{
 | |
| 			input:  "3h",
 | |
| 			expect: 3 * time.Hour,
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "1d",
 | |
| 			expect: day,
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "1d30m",
 | |
| 			expect: day + 30*time.Minute,
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "1m2d",
 | |
| 			expect: time.Minute + day*2,
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "1m2d30s",
 | |
| 			expect: time.Minute + day*2 + 30*time.Second,
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "1d2d",
 | |
| 			expect: 3 * day,
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "1.5d",
 | |
| 			expect: time.Duration(1.5 * float64(day)),
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "4m1.25d",
 | |
| 			expect: 4*time.Minute + time.Duration(1.25*float64(day)),
 | |
| 		},
 | |
| 		{
 | |
| 			input:  "-1.25d12h",
 | |
| 			expect: time.Duration(-1.25*float64(day)) - 12*time.Hour,
 | |
| 		},
 | |
| 	} {
 | |
| 		actual, err := ParseDuration(tc.input)
 | |
| 		if err != nil {
 | |
| 			t.Errorf("Test %d ('%s'): Got error: %v", i, tc.input, err)
 | |
| 			continue
 | |
| 		}
 | |
| 		if actual != tc.expect {
 | |
| 			t.Errorf("Test %d ('%s'): Expected=%s Actual=%s", i, tc.input, tc.expect, actual)
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestEvent_CloudEvent_NilOrigin(t *testing.T) {
 | |
| 	ctx, _ := NewContext(Context{Context: context.Background()}) // module will be nil by default
 | |
| 	event, err := NewEvent(ctx, "started", nil)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("NewEvent() error = %v", err)
 | |
| 	}
 | |
| 
 | |
| 	// This should not panic
 | |
| 	ce := event.CloudEvent()
 | |
| 
 | |
| 	if ce.Source != "caddy" {
 | |
| 		t.Errorf("Expected CloudEvent Source to be 'caddy', got '%s'", ce.Source)
 | |
| 	}
 | |
| 	if ce.Type != "started" {
 | |
| 		t.Errorf("Expected CloudEvent Type to be 'started', got '%s'", ce.Type)
 | |
| 	}
 | |
| }
 |