get.porter.sh/porter@v1.3.0/pkg/mixin/pkgmgmt_test.go (about)

     1  package mixin
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"get.porter.sh/porter/pkg/pkgmgmt"
     8  	"get.porter.sh/porter/pkg/pkgmgmt/client"
     9  	"get.porter.sh/porter/pkg/test"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestRunner_BuildCommand(t *testing.T) {
    14  	testcases := []struct {
    15  		name          string
    16  		runnerCommand string
    17  		wantCommand   string
    18  	}{
    19  		{"build", "build", "/home/myuser/.porter/mixins/exec/exec build\n\\home\\myuser\\.porter\\mixins\\exec\\exec.exe build"},
    20  		{"install", "install", "/home/myuser/.porter/mixins/exec/exec install\n\\home\\myuser\\.porter\\mixins\\exec\\exec.exe install"},
    21  		{"upgrade", "upgrade", "/home/myuser/.porter/mixins/exec/exec upgrade\n\\home\\myuser\\.porter\\mixins\\exec\\exec.exe upgrade"},
    22  		{"uninstall", "uninstall", "/home/myuser/.porter/mixins/exec/exec uninstall\n\\home\\myuser\\.porter\\mixins\\exec\\exec.exe uninstall"},
    23  		{"invoke", "status", "/home/myuser/.porter/mixins/exec/exec invoke --action status\n\\home\\myuser\\.porter\\mixins\\exec\\exec.exe invoke --action status"},
    24  		{"version", "version --output json", "/home/myuser/.porter/mixins/exec/exec version --output json\n\\home\\myuser\\.porter\\mixins\\exec\\exec.exe version --output json"},
    25  	}
    26  
    27  	for _, tc := range testcases {
    28  		t.Run(tc.name, func(t *testing.T) {
    29  			ctx := context.Background()
    30  			r := client.NewTestRunner(t, "exec", "mixins", false)
    31  			r.Setenv(test.ExpectedCommandEnv, tc.wantCommand)
    32  
    33  			mgr := PackageManager{}
    34  			cmd := pkgmgmt.CommandOptions{Command: tc.runnerCommand, PreRun: mgr.PreRunMixinCommandHandler}
    35  			err := r.Run(ctx, cmd)
    36  			require.NoError(t, err)
    37  		})
    38  	}
    39  }