github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/internal/mimetype_helper_test.go (about)

     1  package internal
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_IsArchive(t *testing.T) {
    10  
    11  	tests := []struct {
    12  		name     string
    13  		mimeType string
    14  		expected bool
    15  	}{
    16  		{
    17  			name:     "not an archive",
    18  			mimeType: "application/vnd.unknown",
    19  			expected: false,
    20  		},
    21  		{
    22  			name:     "archive",
    23  			mimeType: "application/x-rar-compressed",
    24  			expected: true,
    25  		},
    26  	}
    27  	for _, test := range tests {
    28  		t.Run(test.name, func(t *testing.T) {
    29  			assert.Equal(t, test.expected, IsArchive(test.mimeType))
    30  		})
    31  	}
    32  }
    33  
    34  func Test_IsExecutable(t *testing.T) {
    35  
    36  	tests := []struct {
    37  		name     string
    38  		mimeType string
    39  		expected bool
    40  	}{
    41  		{
    42  			name:     "not an executable",
    43  			mimeType: "application/vnd.unknown",
    44  			expected: false,
    45  		},
    46  		{
    47  			name:     "executable",
    48  			mimeType: "application/x-mach-binary",
    49  			expected: true,
    50  		},
    51  	}
    52  	for _, test := range tests {
    53  		t.Run(test.name, func(t *testing.T) {
    54  			assert.Equal(t, test.expected, IsExecutable(test.mimeType))
    55  		})
    56  	}
    57  }