github.com/minio/console@v1.3.0/api/logs_test.go (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2022 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package api
    18  
    19  import (
    20  	"flag"
    21  	"fmt"
    22  	"testing"
    23  
    24  	"github.com/minio/cli"
    25  	"github.com/stretchr/testify/assert"
    26  )
    27  
    28  func TestContext_Load(t *testing.T) {
    29  	type fields struct {
    30  		Host           string
    31  		HTTPPort       int
    32  		HTTPSPort      int
    33  		TLSRedirect    string
    34  		TLSCertificate string
    35  		TLSKey         string
    36  		TLSca          string
    37  	}
    38  	type args struct {
    39  		values map[string]string
    40  	}
    41  	tests := []struct {
    42  		name    string
    43  		fields  fields
    44  		args    args
    45  		wantErr bool
    46  	}{
    47  		{
    48  			name: "valid args",
    49  			args: args{
    50  				values: map[string]string{
    51  					"tls-redirect": "on",
    52  				},
    53  			},
    54  			wantErr: false,
    55  		},
    56  		{
    57  			name: "invalid args",
    58  			args: args{
    59  				values: map[string]string{
    60  					"tls-redirect": "aaaa",
    61  				},
    62  			},
    63  			wantErr: true,
    64  		},
    65  		{
    66  			name: "invalid port http",
    67  			args: args{
    68  				values: map[string]string{
    69  					"tls-redirect": "on",
    70  					"port":         "65536",
    71  				},
    72  			},
    73  			wantErr: true,
    74  		},
    75  		{
    76  			name: "invalid port https",
    77  			args: args{
    78  				values: map[string]string{
    79  					"tls-redirect": "on",
    80  					"port":         "65534",
    81  					"tls-port":     "65536",
    82  				},
    83  			},
    84  			wantErr: true,
    85  		},
    86  	}
    87  	for _, tt := range tests {
    88  		t.Run(tt.name, func(_ *testing.T) {
    89  			c := &Context{}
    90  
    91  			fs := flag.NewFlagSet("flags", flag.ContinueOnError)
    92  			for k, v := range tt.args.values {
    93  				fs.String(k, v, "ok")
    94  			}
    95  
    96  			ctx := cli.NewContext(nil, fs, &cli.Context{})
    97  
    98  			err := c.Load(ctx)
    99  			if tt.wantErr {
   100  				assert.NotNilf(t, err, fmt.Sprintf("Load(%v)", err))
   101  			} else {
   102  				assert.Nilf(t, err, fmt.Sprintf("Load(%v)", err))
   103  			}
   104  		})
   105  	}
   106  }
   107  
   108  func Test_logInfo(_ *testing.T) {
   109  	logInfo("message", nil)
   110  }