github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/security_test.go (about)

     1  package services
     2  
     3  import "testing"
     4  
     5  // Test mapping ExpiresIn to expires_in request value and default handling
     6  func TestBuildCreateTokenUrlValuesExpiresIn(t *testing.T) {
     7  	tests := []struct {
     8  		testName string
     9  		input    int
    10  		output   string
    11  	}{
    12  		{"never expires", 0, "0"},
    13  		{"expires", 1800, "1800"},
    14  		{"default", -1, ""},
    15  	}
    16  	for _, test := range tests {
    17  		values := buildCreateTokenUrlValues(CreateTokenParams{
    18  			ExpiresIn: test.input,
    19  		})
    20  		if values.Get("expires_in") != test.output {
    21  			t.Errorf("Test name: %s: Expected: %s, Got: %s", test.testName, test.output, values.Get("expires_in"))
    22  		}
    23  	}
    24  }
    25  
    26  // Test default value -1 in NewCreateTokenParams
    27  func TestNewCreateTokenParams(t *testing.T) {
    28  	values := buildCreateTokenUrlValues(NewCreateTokenParams())
    29  	if values.Get("expires_in") != "" {
    30  		t.Errorf("default expires_in should be empty")
    31  	}
    32  }