github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/framework/auth/auth_test.go (about)

     1  package auth
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/gin-gonic/gin"
     8  )
     9  
    10  func TestGenerate_authentication_token(t *testing.T) {
    11  	type args struct {
    12  		userID    string
    13  		loginName string
    14  		ClientID  string
    15  	}
    16  	tests := []struct {
    17  		name    string
    18  		args    args
    19  		want    string
    20  		want1   string
    21  		want2   string
    22  		wantErr bool
    23  	}{
    24  		// TODO: Add test cases.
    25  	}
    26  	for _, tt := range tests {
    27  		t.Run(tt.name, func(t *testing.T) {
    28  			got, got1, got2, err := Generate_authentication_token(tt.args.userID, tt.args.loginName, tt.args.ClientID)
    29  			if (err != nil) != tt.wantErr {
    30  				t.Errorf("Generate_authentication_token() error = %v, wantErr %v", err, tt.wantErr)
    31  				return
    32  			}
    33  			if got != tt.want {
    34  				t.Errorf("Generate_authentication_token() got = %v, want %v", got, tt.want)
    35  			}
    36  			if got1 != tt.want1 {
    37  				t.Errorf("Generate_authentication_token() got1 = %v, want %v", got1, tt.want1)
    38  			}
    39  			if got2 != tt.want2 {
    40  				t.Errorf("Generate_authentication_token() got2 = %v, want %v", got2, tt.want2)
    41  			}
    42  		})
    43  	}
    44  }
    45  
    46  func TestGetUserInformation(t *testing.T) {
    47  	type args struct {
    48  		ctx *gin.Context
    49  	}
    50  	tests := []struct {
    51  		name    string
    52  		args    args
    53  		want    string
    54  		want1   string
    55  		want2   string
    56  		wantErr bool
    57  	}{
    58  		// TODO: Add test cases.
    59  	}
    60  	for _, tt := range tests {
    61  		t.Run(tt.name, func(t *testing.T) {
    62  			got, got1, got2, err := GetUserInformation(tt.args.ctx)
    63  			if (err != nil) != tt.wantErr {
    64  				t.Errorf("GetUserInformation() error = %v, wantErr %v", err, tt.wantErr)
    65  				return
    66  			}
    67  			if got != tt.want {
    68  				t.Errorf("GetUserInformation() got = %v, want %v", got, tt.want)
    69  			}
    70  			if got1 != tt.want1 {
    71  				t.Errorf("GetUserInformation() got1 = %v, want %v", got1, tt.want1)
    72  			}
    73  			if got2 != tt.want2 {
    74  				t.Errorf("GetUserInformation() got2 = %v, want %v", got2, tt.want2)
    75  			}
    76  		})
    77  	}
    78  }
    79  
    80  func TestValidateToken(t *testing.T) {
    81  	type args struct {
    82  		tokenString string
    83  	}
    84  	tests := []struct {
    85  		name    string
    86  		args    args
    87  		want    bool
    88  		wantErr bool
    89  	}{
    90  		// TODO: Add test cases.
    91  	}
    92  	for _, tt := range tests {
    93  		t.Run(tt.name, func(t *testing.T) {
    94  			got, err := ValidateToken(tt.args.tokenString)
    95  			if (err != nil) != tt.wantErr {
    96  				t.Errorf("ValidateToken() error = %v, wantErr %v", err, tt.wantErr)
    97  				return
    98  			}
    99  			if got != tt.want {
   100  				t.Errorf("ValidateToken() = %v, want %v", got, tt.want)
   101  			}
   102  		})
   103  	}
   104  }
   105  
   106  func TestExtendexptime(t *testing.T) {
   107  	type args struct {
   108  		tokenString string
   109  	}
   110  	tests := []struct {
   111  		name    string
   112  		args    args
   113  		want    string
   114  		want1   string
   115  		want2   string
   116  		wantErr bool
   117  	}{
   118  		// TODO: Add test cases.
   119  	}
   120  	for _, tt := range tests {
   121  		t.Run(tt.name, func(t *testing.T) {
   122  			got, got1, got2, err := Extendexptime(tt.args.tokenString)
   123  			if (err != nil) != tt.wantErr {
   124  				t.Errorf("Extendexptime() error = %v, wantErr %v", err, tt.wantErr)
   125  				return
   126  			}
   127  			if got != tt.want {
   128  				t.Errorf("Extendexptime() got = %v, want %v", got, tt.want)
   129  			}
   130  			if got1 != tt.want1 {
   131  				t.Errorf("Extendexptime() got1 = %v, want %v", got1, tt.want1)
   132  			}
   133  			if got2 != tt.want2 {
   134  				t.Errorf("Extendexptime() got2 = %v, want %v", got2, tt.want2)
   135  			}
   136  		})
   137  	}
   138  }
   139  
   140  func TestAuthMiddleware(t *testing.T) {
   141  	tests := []struct {
   142  		name string
   143  		want gin.HandlerFunc
   144  	}{
   145  		// TODO: Add test cases.
   146  	}
   147  	for _, tt := range tests {
   148  		t.Run(tt.name, func(t *testing.T) {
   149  			if got := AuthMiddleware(); !reflect.DeepEqual(got, tt.want) {
   150  				t.Errorf("AuthMiddleware() = %v, want %v", got, tt.want)
   151  			}
   152  		})
   153  	}
   154  }
   155  
   156  func Test_protectedHandler(t *testing.T) {
   157  	type args struct {
   158  		c *gin.Context
   159  	}
   160  	tests := []struct {
   161  		name string
   162  		args args
   163  	}{
   164  		// TODO: Add test cases.
   165  	}
   166  	for _, tt := range tests {
   167  		t.Run(tt.name, func(t *testing.T) {
   168  			protectedHandler(tt.args.c)
   169  		})
   170  	}
   171  }