storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/event/target/nsq_test.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2018 MinIO, Inc.
     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 target
    18  
    19  import (
    20  	"testing"
    21  
    22  	xnet "storj.io/minio/pkg/net"
    23  )
    24  
    25  func TestNSQArgs_Validate(t *testing.T) {
    26  	type fields struct {
    27  		Enable      bool
    28  		NSQDAddress xnet.Host
    29  		Topic       string
    30  		TLS         struct {
    31  			Enable     bool
    32  			SkipVerify bool
    33  		}
    34  	}
    35  	tests := []struct {
    36  		name    string
    37  		fields  fields
    38  		wantErr bool
    39  	}{
    40  		{
    41  			name: "test1_missing_topic",
    42  			fields: fields{
    43  				Enable: true,
    44  				NSQDAddress: xnet.Host{
    45  					Name:      "127.0.0.1",
    46  					Port:      4150,
    47  					IsPortSet: true,
    48  				},
    49  				Topic: "",
    50  			},
    51  			wantErr: true,
    52  		},
    53  		{
    54  			name: "test2_disabled",
    55  			fields: fields{
    56  				Enable:      false,
    57  				NSQDAddress: xnet.Host{},
    58  				Topic:       "topic",
    59  			},
    60  			wantErr: false,
    61  		},
    62  		{
    63  			name: "test3_OK",
    64  			fields: fields{
    65  				Enable: true,
    66  				NSQDAddress: xnet.Host{
    67  					Name:      "127.0.0.1",
    68  					Port:      4150,
    69  					IsPortSet: true,
    70  				},
    71  				Topic: "topic",
    72  			},
    73  			wantErr: false,
    74  		},
    75  		{
    76  			name: "test4_emptynsqdaddr",
    77  			fields: fields{
    78  				Enable:      true,
    79  				NSQDAddress: xnet.Host{},
    80  				Topic:       "topic",
    81  			},
    82  			wantErr: true,
    83  		},
    84  	}
    85  	for _, tt := range tests {
    86  		t.Run(tt.name, func(t *testing.T) {
    87  			n := NSQArgs{
    88  				Enable:      tt.fields.Enable,
    89  				NSQDAddress: tt.fields.NSQDAddress,
    90  				Topic:       tt.fields.Topic,
    91  			}
    92  			if err := n.Validate(); (err != nil) != tt.wantErr {
    93  				t.Errorf("NSQArgs.Validate() error = %v, wantErr %v", err, tt.wantErr)
    94  			}
    95  		})
    96  	}
    97  }