github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/fleetspeak/src/server/components/components_test.go (about) 1 // Copyright 2019 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package components 16 17 import ( 18 "testing" 19 20 cpb "github.com/google/fleetspeak/fleetspeak/src/server/components/proto/fleetspeak_components" 21 ) 22 23 func TestValidation(t *testing.T) { 24 for _, tc := range []struct { 25 cfg *cpb.Config 26 wantErr string 27 }{ 28 { 29 cfg: &cpb.Config{}, 30 wantErr: "mysql_data_source_name is required", 31 }, 32 { 33 cfg: &cpb.Config{ 34 MysqlDataSourceName: "fs:seecret@tcp(localhost:1234)/fsdb", 35 HttpsConfig: &cpb.HttpsConfig{ 36 ListenAddress: "localhost:443", 37 }, 38 }, 39 wantErr: "https_config requires listen_address, certificates and key", 40 }, 41 { 42 cfg: &cpb.Config{ 43 MysqlDataSourceName: "fs:seecret@tcp(localhost:1234)/fsdb", 44 HttpsConfig: &cpb.HttpsConfig{ 45 ListenAddress: "localhost:443", 46 Certificates: "<>", 47 Key: "<>", 48 }, 49 AdminConfig: &cpb.AdminConfig{}, 50 }, 51 wantErr: "admin_config.listen_address can't be empty", 52 }, 53 } { 54 _, err := MakeComponents(tc.cfg) 55 if err == nil || err.Error() != tc.wantErr { 56 t.Errorf("Expected error message [%v], got [%v]", tc.wantErr, err) 57 } 58 } 59 }