Skip to content

Commit 389851e

Browse files
committed
Improve unittest
1. change package from cas_test to cas 2. change dependences of gopkg.in/cas.v1 in test files
1 parent cb067e8 commit 389851e

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

doc_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
package cas_test
1+
package cas
22

33
import (
44
"fmt"
55
"log"
66
"net/http"
77
"net/url"
8-
9-
"gopkg.in/cas.v1"
108
)
119

1210
func ExampleRedirectToLogin() {
1311
u, _ := url.Parse("https://cas.example.com")
14-
c := cas.NewClient(&cas.Options{
12+
c := NewClient(&Options{
1513
URL: u,
1614
})
1715

1816
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
19-
cas.RedirectToLogin(w, r)
17+
RedirectToLogin(w, r)
2018
})
2119

2220
err := http.ListenAndServe(":8080", h)
@@ -27,12 +25,12 @@ func ExampleRedirectToLogin() {
2725

2826
func ExampleRedirectToLogout() {
2927
u, _ := url.Parse("https://cas.example.com")
30-
c := cas.NewClient(&cas.Options{
28+
c := NewClient(&Options{
3129
URL: u,
3230
})
3331

3432
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
35-
cas.RedirectToLogout(w, r)
33+
RedirectToLogout(w, r)
3634
})
3735

3836
err := http.ListenAndServe(":8080", h)
@@ -43,13 +41,13 @@ func ExampleRedirectToLogout() {
4341

4442
func ExampleIsAuthenticated() {
4543
u, _ := url.Parse("https://cas.example.com")
46-
c := cas.NewClient(&cas.Options{
44+
c := NewClient(&Options{
4745
URL: u,
4846
})
4947

5048
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
51-
if !cas.IsAuthenticated(r) {
52-
cas.RedirectToLogout(w, r)
49+
if !IsAuthenticated(r) {
50+
RedirectToLogout(w, r)
5351
}
5452

5553
fmt.Fprintf(w, "Hello World\n")
@@ -63,16 +61,16 @@ func ExampleIsAuthenticated() {
6361

6462
func ExampleUsername() {
6563
u, _ := url.Parse("https://cas.example.com")
66-
c := cas.NewClient(&cas.Options{
64+
c := NewClient(&Options{
6765
URL: u,
6866
})
6967

7068
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
71-
if !cas.IsAuthenticated(r) {
72-
cas.RedirectToLogout(w, r)
69+
if !IsAuthenticated(r) {
70+
RedirectToLogout(w, r)
7371
}
7472

75-
fmt.Fprintf(w, "Hello %s\n", cas.Username(r))
73+
fmt.Fprintf(w, "Hello %s\n", Username(r))
7674
})
7775

7876
err := http.ListenAndServe(":8080", h)

example_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cas_test
1+
package cas
22

33
import (
44
"bytes"
@@ -9,8 +9,6 @@ import (
99
"net/url"
1010

1111
"github.com/golang/glog"
12-
13-
"gopkg.in/cas.v1"
1412
)
1513

1614
type myHandler struct{}
@@ -40,7 +38,7 @@ func Example() {
4038
m.Handle("/", MyHandler)
4139

4240
url, _ := url.Parse(casURL)
43-
client := cas.NewClient(&cas.Options{
41+
client := NewClient(&Options{
4442
URL: url,
4543
})
4644

@@ -58,17 +56,17 @@ func Example() {
5856

5957
type templateBinding struct {
6058
Username string
61-
Attributes cas.UserAttributes
59+
Attributes UserAttributes
6260
}
6361

6462
func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
65-
if !cas.IsAuthenticated(r) {
66-
cas.RedirectToLogin(w, r)
63+
if !IsAuthenticated(r) {
64+
RedirectToLogin(w, r)
6765
return
6866
}
6967

7068
if r.URL.Path == "/logout" {
71-
cas.RedirectToLogout(w, r)
69+
RedirectToLogout(w, r)
7270
return
7371
}
7472

@@ -83,8 +81,8 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8381
}
8482

8583
binding := &templateBinding{
86-
Username: cas.Username(r),
87-
Attributes: cas.Attributes(r),
84+
Username: Username(r),
85+
Attributes: Attributes(r),
8886
}
8987

9088
html := new(bytes.Buffer)

0 commit comments

Comments
 (0)