github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/event/target/nsq_test.go (about) 1 // Copyright (c) 2015-2023 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package target 19 20 import ( 21 "testing" 22 23 xnet "github.com/minio/pkg/v2/net" 24 ) 25 26 func TestNSQArgs_Validate(t *testing.T) { 27 type fields struct { 28 Enable bool 29 NSQDAddress xnet.Host 30 Topic string 31 TLS struct { 32 Enable bool 33 SkipVerify bool 34 } 35 } 36 tests := []struct { 37 name string 38 fields fields 39 wantErr bool 40 }{ 41 { 42 name: "test1_missing_topic", 43 fields: fields{ 44 Enable: true, 45 NSQDAddress: xnet.Host{ 46 Name: "127.0.0.1", 47 Port: 4150, 48 IsPortSet: true, 49 }, 50 Topic: "", 51 }, 52 wantErr: true, 53 }, 54 { 55 name: "test2_disabled", 56 fields: fields{ 57 Enable: false, 58 NSQDAddress: xnet.Host{}, 59 Topic: "topic", 60 }, 61 wantErr: false, 62 }, 63 { 64 name: "test3_OK", 65 fields: fields{ 66 Enable: true, 67 NSQDAddress: xnet.Host{ 68 Name: "127.0.0.1", 69 Port: 4150, 70 IsPortSet: true, 71 }, 72 Topic: "topic", 73 }, 74 wantErr: false, 75 }, 76 { 77 name: "test4_emptynsqdaddr", 78 fields: fields{ 79 Enable: true, 80 NSQDAddress: xnet.Host{}, 81 Topic: "topic", 82 }, 83 wantErr: true, 84 }, 85 } 86 for _, tt := range tests { 87 t.Run(tt.name, func(t *testing.T) { 88 n := NSQArgs{ 89 Enable: tt.fields.Enable, 90 NSQDAddress: tt.fields.NSQDAddress, 91 Topic: tt.fields.Topic, 92 } 93 if err := n.Validate(); (err != nil) != tt.wantErr { 94 t.Errorf("NSQArgs.Validate() error = %v, wantErr %v", err, tt.wantErr) 95 } 96 }) 97 } 98 }