github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/reportsizes/reportsizes_test.go (about)

     1  package reportsizes
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/goreleaser/goreleaser/internal/artifact"
     9  	"github.com/goreleaser/goreleaser/internal/testctx"
    10  	"github.com/goreleaser/goreleaser/pkg/config"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestString(t *testing.T) {
    15  	require.NotEmpty(t, Pipe{}.String())
    16  }
    17  
    18  func TestSkip(t *testing.T) {
    19  	t.Run("skip", func(t *testing.T) {
    20  		require.True(t, Pipe{}.Skip(testctx.New()))
    21  	})
    22  	t.Run("dont skip", func(t *testing.T) {
    23  		require.False(t, Pipe{}.Skip(testctx.NewWithCfg(config.Project{
    24  			ReportSizes: true,
    25  		})))
    26  	})
    27  }
    28  
    29  func TestRun(t *testing.T) {
    30  	ctx := testctx.New()
    31  	for i, tp := range []artifact.Type{
    32  		artifact.Binary,
    33  		artifact.UniversalBinary,
    34  		artifact.UploadableArchive,
    35  		artifact.PublishableSnapcraft,
    36  		artifact.LinuxPackage,
    37  		artifact.CArchive,
    38  		artifact.CShared,
    39  		artifact.Header,
    40  	} {
    41  		if i%2 == 0 {
    42  			cw, err := os.Getwd()
    43  			require.NoError(t, err)
    44  			ctx.Artifacts.Add(&artifact.Artifact{
    45  				Name:  "foo",
    46  				Path:  filepath.Join(cw, "reportsizes.go"),
    47  				Extra: map[string]any{},
    48  				Type:  tp,
    49  			})
    50  			continue
    51  		}
    52  		ctx.Artifacts.Add(&artifact.Artifact{
    53  			Name:  "foo",
    54  			Path:  "reportsizes.go",
    55  			Extra: map[string]any{},
    56  			Type:  tp,
    57  		})
    58  	}
    59  
    60  	require.NoError(t, Pipe{}.Run(ctx))
    61  
    62  	for _, art := range ctx.Artifacts.List() {
    63  		require.NotZero(t, artifact.ExtraOr[int64](*art, artifact.ExtraSize, 0))
    64  	}
    65  }