github.com/andrewhsu/cli/v2@v2.0.1-0.20210910131313-d4b4061f5b89/pkg/cmd/release/shared/upload_test.go (about)

     1  package shared
     2  
     3  import "testing"
     4  
     5  func Test_typeForFilename(t *testing.T) {
     6  	tests := []struct {
     7  		name string
     8  		file string
     9  		want string
    10  	}{
    11  		{
    12  			name: "tar",
    13  			file: "ball.tar",
    14  			want: "application/x-tar",
    15  		},
    16  		{
    17  			name: "tgz",
    18  			file: "ball.tgz",
    19  			want: "application/x-gtar",
    20  		},
    21  		{
    22  			name: "tar.gz",
    23  			file: "ball.tar.gz",
    24  			want: "application/x-gtar",
    25  		},
    26  		{
    27  			name: "bz2",
    28  			file: "ball.tar.bz2",
    29  			want: "application/x-bzip2",
    30  		},
    31  		{
    32  			name: "zip",
    33  			file: "archive.zip",
    34  			want: "application/zip",
    35  		},
    36  		{
    37  			name: "js",
    38  			file: "app.js",
    39  			want: "application/javascript",
    40  		},
    41  		{
    42  			name: "dmg",
    43  			file: "apple.dmg",
    44  			want: "application/x-apple-diskimage",
    45  		},
    46  		{
    47  			name: "rpm",
    48  			file: "package.rpm",
    49  			want: "application/x-rpm",
    50  		},
    51  		{
    52  			name: "deb",
    53  			file: "package.deb",
    54  			want: "application/x-debian-package",
    55  		},
    56  		{
    57  			name: "no extension",
    58  			file: "myfile",
    59  			want: "application/octet-stream",
    60  		},
    61  	}
    62  	for _, tt := range tests {
    63  		t.Run(tt.file, func(t *testing.T) {
    64  			if got := typeForFilename(tt.file); got != tt.want {
    65  				t.Errorf("typeForFilename() = %v, want %v", got, tt.want)
    66  			}
    67  		})
    68  	}
    69  }