github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/credential/insecure_test.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package credential
    18  
    19  import (
    20  	"net/http"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  func Test_insecureCredential_Auth(t *testing.T) {
    27  	t.Parallel()
    28  
    29  	tests := []struct {
    30  		name    string
    31  		want    AuthInfo
    32  		wantErr bool
    33  	}{
    34  		{
    35  			name:    "no auth info",
    36  			want:    AnonymousAuthInfo{},
    37  			wantErr: false,
    38  		},
    39  	}
    40  	for _, tt := range tests {
    41  		tt := tt
    42  		t.Run(tt.name, func(t *testing.T) {
    43  			t.Parallel()
    44  			i := &insecureCredential{}
    45  			got, err := i.Auth(&http.Request{})
    46  			assert.Equal(t, tt.want, got)
    47  			assert.Equal(t, tt.wantErr, err != nil)
    48  		})
    49  	}
    50  }
    51  
    52  func Test_insecureCredential_AuthToken(t *testing.T) {
    53  	t.Parallel()
    54  
    55  	tests := []struct {
    56  		name    string
    57  		want    AuthInfo
    58  		wantErr bool
    59  	}{
    60  		{
    61  			name:    "no auth info",
    62  			want:    AnonymousAuthInfo{},
    63  			wantErr: false,
    64  		},
    65  	}
    66  	for _, tt := range tests {
    67  		tt := tt
    68  		t.Run(tt.name, func(t *testing.T) {
    69  			t.Parallel()
    70  			i := &insecureCredential{}
    71  			got, err := i.AuthToken("")
    72  			assert.Equal(t, tt.want, got)
    73  			assert.Equal(t, tt.wantErr, err != nil)
    74  		})
    75  	}
    76  }