github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/fanal/utils/utils_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"bufio"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  )
     9  
    10  func TestIsGzip(t *testing.T) {
    11  	var tests = []struct {
    12  		in   string
    13  		want bool
    14  	}{
    15  		{filepath.Join("testdata", "test.txt.gz"), true},
    16  		{filepath.Join("testdata", "test.tar.gz"), true},
    17  		{filepath.Join("testdata", "test.txt"), false},
    18  		{filepath.Join("testdata", "test.txt.zst"), false},
    19  		{filepath.Join("testdata", "aqua.png"), false},
    20  	}
    21  	for _, tt := range tests {
    22  		t.Run(tt.in, func(t *testing.T) {
    23  			f, err := os.Open(tt.in)
    24  			if err != nil {
    25  				t.Fatalf("unknown error: %s", err)
    26  			}
    27  
    28  			got := IsGzip(bufio.NewReader(f))
    29  			if got != tt.want {
    30  				t.Errorf("got %t, want %t", got, tt.want)
    31  			}
    32  		})
    33  	}
    34  }