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

     1  package services
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestCalculateMinimumBuildDate(t *testing.T) {
     9  
    10  	layout := "2006-01-02T15:04:05.000-0700"
    11  	time1, _ := time.Parse(layout, "2018-05-07T17:34:49.729+0300")
    12  	time2, _ := time.Parse(layout, "2018-05-07T17:34:49.729+0300")
    13  	time3, _ := time.Parse(layout, "2018-05-07T17:34:49.729+0300")
    14  
    15  	tests := []struct {
    16  		testName      string
    17  		startingDate  time.Time
    18  		maxDaysString string
    19  		expectedTime  string
    20  	}{
    21  		{"test_max_days=3", time1, "3", "2018-05-04T17:34:49.729+0300"},
    22  		{"test_max_days=0", time2, "0", "2018-05-07T17:34:49.729+0300"},
    23  		{"test_max_days=-1", time3, "-3", "2018-05-10T17:34:49.729+0300"},
    24  	}
    25  
    26  	for _, test := range tests {
    27  		t.Run(test.testName, func(t *testing.T) {
    28  			actual, _ := calculateMinimumBuildDate(test.startingDate, test.maxDaysString)
    29  			if test.expectedTime != actual {
    30  				t.Errorf("Test name: %s: Expected: %s, Got: %s", test.testName, test.expectedTime, actual)
    31  			}
    32  		})
    33  	}
    34  }