go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/types/types_test.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package types
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestTypes(t *testing.T) {
    13  	list := []struct {
    14  		T             Type
    15  		ExpectedLabel string
    16  	}{
    17  		{
    18  			T: Unset, ExpectedLabel: "unset",
    19  		}, {
    20  			T: Any, ExpectedLabel: "any",
    21  		}, {
    22  			T: Nil, ExpectedLabel: "null",
    23  		}, {
    24  			T: Ref, ExpectedLabel: "ref",
    25  		}, {
    26  			T: Bool, ExpectedLabel: "bool",
    27  		}, {
    28  			T: Int, ExpectedLabel: "int",
    29  		}, {
    30  			T: Float, ExpectedLabel: "float",
    31  		}, {
    32  			T: String, ExpectedLabel: "string",
    33  		}, {
    34  			T: Regex, ExpectedLabel: "regex",
    35  		}, {
    36  			T: Time, ExpectedLabel: "time",
    37  		}, {
    38  			T: Dict, ExpectedLabel: "dict",
    39  		}, {
    40  			T: Score, ExpectedLabel: "score",
    41  		}, {
    42  			T: Array(String), ExpectedLabel: "[]string",
    43  		}, {
    44  			T: Map(String, String), ExpectedLabel: "map[string]string",
    45  		}, {
    46  			T: Resource("mockresource"), ExpectedLabel: "mockresource",
    47  		}, {
    48  			T: Function('f', []Type{String, Int}), ExpectedLabel: "function(..??..)",
    49  		},
    50  	}
    51  
    52  	for i := range list {
    53  		test := list[i]
    54  
    55  		// test for human friendly name
    56  		assert.Equal(t, test.ExpectedLabel, test.T.Label())
    57  	}
    58  }