github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/cli_test.go (about)

     1  package artifactory
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestValidateGoNativeCommand(t *testing.T) {
     8  	tests := []struct {
     9  		name     string
    10  		args     []string
    11  		expected bool
    12  	}{
    13  		{"withInvalidCommand", []string{"build", "-test", "-another", "--publish-deps"}, true},
    14  		{"withSimilarCommand", []string{"build", "-test", "-another", "publish-deps"}, false},
    15  		{"withoutAnyFlags", []string{"build", "-test", "-another"}, false},
    16  		{"withFlagAndValue", []string{"build", "-test", "-another", "--url=http://another.com"}, true},
    17  	}
    18  
    19  	for _, test := range tests {
    20  		t.Run(test.name, func(t *testing.T) {
    21  			result := validateCommand(test.args, getGoFlags())
    22  			if result != nil && !test.expected {
    23  				t.Errorf("Expected error nil, got the following error %s", result)
    24  			}
    25  
    26  			if result == nil && test.expected {
    27  				t.Errorf("Expected error, howerver, got nil")
    28  			}
    29  		})
    30  	}
    31  }