dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/models/log_entry_test.go (about) 1 /******************************************************************************* 2 * Copyright 2019 Dell Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 *******************************************************************************/ 14 15 package models_test 16 17 import ( 18 "testing" 19 20 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models" 21 "github.com/stretchr/testify/require" 22 ) 23 24 var testLogEntry = models.LogEntry{Level: models.InfoLog, Created: 123, Message: "We logged some stuff"} 25 26 func TestLogEntryValidation(t *testing.T) { 27 valid := testLogEntry 28 29 invalid := testLogEntry 30 invalid.Level = "blah" 31 32 blank := testLogEntry 33 blank.Level = "" 34 35 tests := []struct { 36 name string 37 le models.LogEntry 38 expectError bool 39 }{ 40 {"valid log entry", valid, false}, 41 {"invalid log level", invalid, true}, 42 {"blank log level", blank, true}, 43 } 44 for _, tt := range tests { 45 t.Run(tt.name, func(t *testing.T) { 46 _, err := tt.le.Validate() 47 if tt.expectError { 48 require.Error(t, err) 49 } else { 50 require.NoError(t, err) 51 } 52 }) 53 } 54 }