github.com/cnotch/ipchub@v1.1.0/provider/auth/user_test.go (about)

     1  // Copyright (c) 2019,CAOHONGJU All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package auth
     6  
     7  import "testing"
     8  
     9  func TestUser_ValidePermission(t *testing.T) {
    10  	u := User{
    11  		Name:       "cao",
    12  		Password:   "ok",
    13  		PushAccess: "/a/+/c",
    14  		PullAccess: "/a/*",
    15  	}
    16  	u.init()
    17  
    18  	tests := []struct {
    19  		name  string
    20  		path  string
    21  		right AccessRight
    22  		want  bool
    23  	}{
    24  		{"2", "/a/b/c", PushRight, true},
    25  		{"3", "/a/c", PushRight, false},
    26  		{"4", "/a", PullRight, true},
    27  		{"5", "/a/c", PullRight, true},
    28  		{"6", "/a/c/d", PullRight, true},
    29  	}
    30  	for _, tt := range tests {
    31  		t.Run(tt.name, func(t *testing.T) {
    32  			if got := u.ValidatePermission(tt.path, tt.right); got != tt.want {
    33  				t.Errorf("User.ValidePermission() = %v, want %v", got, tt.want)
    34  			}
    35  		})
    36  	}
    37  }