go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/detector/detector_test.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package detector 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "go.mondoo.com/cnquery/providers-sdk/v1/inventory" 11 ) 12 13 func TestFamilyParents(t *testing.T) { 14 test := []struct { 15 Platform string 16 Expected []string 17 }{ 18 { 19 Platform: "redhat", 20 Expected: []string{"os", "unix", "linux", "redhat"}, 21 }, 22 { 23 Platform: "centos", 24 Expected: []string{"os", "unix", "linux", "redhat"}, 25 }, 26 { 27 Platform: "debian", 28 Expected: []string{"os", "unix", "linux", "debian"}, 29 }, 30 { 31 Platform: "ubuntu", 32 Expected: []string{"os", "unix", "linux", "debian"}, 33 }, 34 } 35 36 for i := range test { 37 assert.Equal(t, test[i].Expected, Family(test[i].Platform), test[i].Platform) 38 } 39 } 40 41 func TestIsFamily(t *testing.T) { 42 test := []struct { 43 Val bool 44 Expected bool 45 }{ 46 { 47 Val: IsFamily("redhat", inventory.FAMILY_LINUX), 48 Expected: true, 49 }, 50 { 51 Val: IsFamily("redhat", inventory.FAMILY_UNIX), 52 Expected: true, 53 }, 54 { 55 Val: IsFamily("redhat", "redhat"), 56 Expected: true, 57 }, 58 { 59 Val: IsFamily("centos", inventory.FAMILY_LINUX), 60 Expected: true, 61 }, 62 { 63 Val: IsFamily("centos", "redhat"), 64 Expected: true, 65 }, 66 } 67 68 for i := range test { 69 assert.Equal(t, test[i].Expected, test[i].Val, i) 70 } 71 }