github.com/shipa-corp/ketch@v0.6.0/cmd/ketch/builder_set_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/BurntSushi/toml"
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/shipa-corp/ketch/cmd/ketch/configuration"
    12  )
    13  
    14  func Test_newBuilderSetCmd(t *testing.T) {
    15  	type args struct {
    16  		ketchConfig   configuration.KetchConfig
    17  		defaultBulder string
    18  	}
    19  	tests := []struct {
    20  		name    string
    21  		args    args
    22  		wantErr bool
    23  	}{
    24  		{
    25  			name: "successfully write to file",
    26  			args: args{
    27  				ketchConfig: configuration.KetchConfig{
    28  					DefaultBuilder: "oldDefault",
    29  				},
    30  				defaultBulder: "newDefault",
    31  			},
    32  		},
    33  	}
    34  	for _, tt := range tests {
    35  		t.Run(tt.name, func(t *testing.T) {
    36  			rootPath := t.TempDir()
    37  			fullPath := filepath.Join(rootPath, "config.toml")
    38  			os.Setenv("KETCH_HOME", rootPath)
    39  
    40  			cmd := newBuilderSetCmd(tt.args.ketchConfig)
    41  			cmd.SetArgs([]string{tt.args.defaultBulder})
    42  			err := cmd.Execute()
    43  			require.Nil(t, err)
    44  
    45  			var ketchConfig configuration.KetchConfig
    46  			_, err = toml.DecodeFile(fullPath, &ketchConfig)
    47  			require.Nil(t, err)
    48  
    49  			require.Equal(t, tt.args.defaultBulder, ketchConfig.DefaultBuilder)
    50  		})
    51  	}
    52  }