github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/syftjson/model/linux_release_test.go (about)

     1  package model
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestIDLikes_UnmarshalJSON(t *testing.T) {
    12  	tests := []struct {
    13  		name     string
    14  		data     interface{}
    15  		expected IDLikes
    16  	}{
    17  		{
    18  			name: "single string",
    19  			data: "well hello there!",
    20  			expected: IDLikes{
    21  				"well hello there!",
    22  			},
    23  		},
    24  		{
    25  			name: "multiple strings",
    26  			data: []string{
    27  				"well hello there!",
    28  				"...hello there, john!",
    29  			},
    30  			expected: IDLikes{
    31  				"well hello there!",
    32  				"...hello there, john!",
    33  			},
    34  		},
    35  	}
    36  	for _, tt := range tests {
    37  		t.Run(tt.name, func(t *testing.T) {
    38  			data, err := json.Marshal(&tt.data)
    39  			require.NoError(t, err)
    40  
    41  			var obj IDLikes
    42  			require.NoError(t, json.Unmarshal(data, &obj))
    43  
    44  			assert.Equal(t, tt.expected, obj)
    45  		})
    46  	}
    47  }