| 1 |
package op_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/stretchr/testify/require" |
| 7 |
"github.com/zitadel/oidc/v3/pkg/op" |
| 8 |
) |
| 9 |
|
| 10 |
func TestEndpoint_Path(t *testing.T) { |
| 11 |
tests := []struct { |
| 12 |
name string |
| 13 |
e *op.Endpoint |
| 14 |
want string |
| 15 |
}{ |
| 16 |
{ |
| 17 |
"without starting /", |
| 18 |
op.NewEndpoint("test"), |
| 19 |
"/test", |
| 20 |
}, |
| 21 |
{ |
| 22 |
"with starting /", |
| 23 |
op.NewEndpoint("/test"), |
| 24 |
"/test", |
| 25 |
}, |
| 26 |
{ |
| 27 |
"with url", |
| 28 |
op.NewEndpointWithURL("/test", "http://test.com/test"), |
| 29 |
"/test", |
| 30 |
}, |
| 31 |
{ |
| 32 |
"nil", |
| 33 |
nil, |
| 34 |
"", |
| 35 |
}, |
| 36 |
} |
| 37 |
for _, tt := range tests { |
| 38 |
t.Run(tt.name, func(t *testing.T) { |
| 39 |
if got := tt.e.Relative(); got != tt.want { |
| 40 |
t.Errorf("Endpoint.Relative() = %v, want %v", got, tt.want) |
| 41 |
} |
| 42 |
}) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func TestEndpoint_Absolute(t *testing.T) { |
| 47 |
type args struct { |
| 48 |
host string |
| 49 |
} |
| 50 |
tests := []struct { |
| 51 |
name string |
| 52 |
e *op.Endpoint |
| 53 |
args args |
| 54 |
want string |
| 55 |
}{ |
| 56 |
{ |
| 57 |
"no /", |
| 58 |
op.NewEndpoint("test"), |
| 59 |
args{"https://host"}, |
| 60 |
"https://host/test", |
| 61 |
}, |
| 62 |
{ |
| 63 |
"endpoint without /", |
| 64 |
op.NewEndpoint("test"), |
| 65 |
args{"https://host/"}, |
| 66 |
"https://host/test", |
| 67 |
}, |
| 68 |
{ |
| 69 |
"host without /", |
| 70 |
op.NewEndpoint("/test"), |
| 71 |
args{"https://host"}, |
| 72 |
"https://host/test", |
| 73 |
}, |
| 74 |
{ |
| 75 |
"both /", |
| 76 |
op.NewEndpoint("/test"), |
| 77 |
args{"https://host/"}, |
| 78 |
"https://host/test", |
| 79 |
}, |
| 80 |
{ |
| 81 |
"with url", |
| 82 |
op.NewEndpointWithURL("test", "https://test.com/test"), |
| 83 |
args{"https://host"}, |
| 84 |
"https://test.com/test", |
| 85 |
}, |
| 86 |
{ |
| 87 |
"nil", |
| 88 |
nil, |
| 89 |
args{"https://host"}, |
| 90 |
"", |
| 91 |
}, |
| 92 |
} |
| 93 |
for _, tt := range tests { |
| 94 |
t.Run(tt.name, func(t *testing.T) { |
| 95 |
if got := tt.e.Absolute(tt.args.host); got != tt.want { |
| 96 |
t.Errorf("Endpoint.Absolute() = %v, want %v", got, tt.want) |
| 97 |
} |
| 98 |
}) |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
// TODO: impl test |
| 103 |
func TestEndpoint_Validate(t *testing.T) { |
| 104 |
tests := []struct { |
| 105 |
name string |
| 106 |
e *op.Endpoint |
| 107 |
wantErr error |
| 108 |
}{ |
| 109 |
{ |
| 110 |
"nil", |
| 111 |
nil, |
| 112 |
op.ErrNilEndpoint, |
| 113 |
}, |
| 114 |
} |
| 115 |
for _, tt := range tests { |
| 116 |
t.Run(tt.name, func(t *testing.T) { |
| 117 |
err := tt.e.Validate() |
| 118 |
require.ErrorIs(t, err, tt.wantErr) |
| 119 |
}) |
| 120 |
} |
| 121 |
} |