...

Source file src/github.com/redhat-developer/odo/pkg/libdevfile/command_test.go

Documentation: github.com/redhat-developer/odo/pkg/libdevfile

     1  package libdevfile
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
     8  	"github.com/devfile/library/v2/pkg/devfile/parser"
     9  	"github.com/devfile/library/v2/pkg/devfile/parser/data"
    10  	"github.com/redhat-developer/odo/pkg/libdevfile/generator"
    11  	"k8s.io/utils/pointer"
    12  )
    13  
    14  func Test_newCommand(t *testing.T) {
    15  
    16  	execCommand := generator.GetExecCommand(generator.ExecCommandParams{
    17  		Kind:      v1alpha2.RunCommandGroupKind,
    18  		Id:        "exec-command",
    19  		IsDefault: pointer.Bool(true),
    20  	})
    21  	compositeCommand := generator.GetCompositeCommand(generator.CompositeCommandParams{
    22  		Kind:      v1alpha2.DeployCommandGroupKind,
    23  		Id:        "composite-command",
    24  		IsDefault: pointer.Bool(true),
    25  	})
    26  	applyCommand := generator.GetApplyCommand(generator.ApplyCommandParams{
    27  		Kind:      v1alpha2.DeployCommandGroupKind,
    28  		Id:        "apply-command",
    29  		IsDefault: pointer.Bool(false),
    30  	})
    31  
    32  	data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
    33  	_ = data.AddCommands([]v1alpha2.Command{execCommand, compositeCommand, applyCommand})
    34  	devfileObj := parser.DevfileObj{
    35  		Data: data,
    36  	}
    37  
    38  	type args struct {
    39  		devfileObj parser.DevfileObj
    40  		devfileCmd v1alpha2.Command
    41  	}
    42  	tests := []struct {
    43  		name     string
    44  		args     args
    45  		wantType string
    46  		wantErr  bool
    47  	}{
    48  		{
    49  			name: "exec command",
    50  			args: args{
    51  				devfileObj: devfileObj,
    52  				devfileCmd: execCommand,
    53  			},
    54  			wantType: "*libdevfile.execCommand",
    55  		},
    56  		{
    57  			name: "composite command",
    58  			args: args{
    59  				devfileObj: devfileObj,
    60  				devfileCmd: compositeCommand,
    61  			},
    62  			wantType: "*libdevfile.compositeCommand",
    63  		},
    64  		{
    65  			name: "apply command",
    66  			args: args{
    67  				devfileObj: devfileObj,
    68  				devfileCmd: applyCommand,
    69  			},
    70  			wantType: "*libdevfile.applyCommand",
    71  		},
    72  		// TODO: Add test cases.
    73  	}
    74  	for _, tt := range tests {
    75  		t.Run(tt.name, func(t *testing.T) {
    76  			got, err := newCommand(tt.args.devfileObj, tt.args.devfileCmd)
    77  			if (err != nil) != tt.wantErr {
    78  				t.Errorf("newCommand() error = %v, wantErr %v", err, tt.wantErr)
    79  				return
    80  			}
    81  
    82  			gotType := fmt.Sprintf("%T", got)
    83  			if gotType != tt.wantType {
    84  				t.Errorf("newCommand() type = %v, want %v", got, tt.wantType)
    85  			}
    86  		})
    87  	}
    88  }
    89  

View as plain text