Debian Codegraph @

caddy_test.go

raw symbols SCIP
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/
16
17 import (
18 "contextscip-go gomod github.com/golang/go/src go1.25.1 context/"
19 "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/"
20 "timescip-go gomod github.com/golang/go/src go1.25.1 time/"
21 )
22
23 func TestParseDurationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/TestParseDuration().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
24 const day = 24 * timescip-go gomod github.com/golang/go/src go1.25.1 time/.Hourscip-go gomod github.com/golang/go/src go1.25.1 time/Hour.
25 for i, tc := range []struct {
26 input string
27 expect timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#
28 }{
29 {
30 input: "3h",
31 expect: 3 * timescip-go gomod github.com/golang/go/src go1.25.1 time/.Hourscip-go gomod github.com/golang/go/src go1.25.1 time/Hour.,
32 },
33 {
34 input: "1d",
35 expect: day,
36 },
37 {
38 input: "1d30m",
39 expect: day + 30*timescip-go gomod github.com/golang/go/src go1.25.1 time/.Minutescip-go gomod github.com/golang/go/src go1.25.1 time/Minute.,
40 },
41 {
42 input: "1m2d",
43 expect: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Minutescip-go gomod github.com/golang/go/src go1.25.1 time/Minute. + day*2,
44 },
45 {
46 input: "1m2d30s",
47 expect: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Minutescip-go gomod github.com/golang/go/src go1.25.1 time/Minute. + day*2 + 30*timescip-go gomod github.com/golang/go/src go1.25.1 time/.Secondscip-go gomod github.com/golang/go/src go1.25.1 time/Second.,
48 },
49 {
50 input: "1d2d",
51 expect: 3 * day,
52 },
53 {
54 input: "1.5d",
55 expect: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(1.5 * float64(day)),
56 },
57 {
58 input: "4m1.25d",
59 expect: 4*timescip-go gomod github.com/golang/go/src go1.25.1 time/.Minutescip-go gomod github.com/golang/go/src go1.25.1 time/Minute. + timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(1.25*float64(day)),
60 },
61 {
62 input: "-1.25d12h",
63 expect: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(-1.25*float64(day)) - 12*timescip-go gomod github.com/golang/go/src go1.25.1 time/.Hourscip-go gomod github.com/golang/go/src go1.25.1 time/Hour.,
64 },
65 } {
66 actual, err := ParseDurationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ParseDuration().(tc.input)
67 if err != nil {
68 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d ('%s'): Got error: %v", i, tc.input, err)
69 continue
70 }
71 if actual != tc.expect {
72 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d ('%s'): Expected=%s Actual=%s", i, tc.input, tc.expect, actual)
73 }
74 }
75 }
76
77 func TestEvent_CloudEvent_NilOriginscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/TestEvent_CloudEvent_NilOrigin().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
78 ctx, _ := NewContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewContext().(Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#{Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Context.: contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.1 context/Background().()}) // module will be nil by default
79 event, err := NewEventscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewEvent().(ctx, "started", nil)
80 if err != nil {
81 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("NewEvent() error = %v", err)
82 }
83
84 // This should not panic
85 ce := event.CloudEventscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Event#CloudEvent().()
86
87 if ce.Sourcescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CloudEvent#Source. != "caddy" {
88 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Expected CloudEvent Source to be 'caddy', got '%s'", ce.Sourcescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CloudEvent#Source.)
89 }
90 if ce.Typescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CloudEvent#Type. != "started" {
91 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Expected CloudEvent Type to be 'started', got '%s'", ce.Typescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CloudEvent#Type.)
92 }
93 }