Skip to content

Commit

Permalink
test: add unit tests for the expiration date function
Browse files Browse the repository at this point in the history
Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
  • Loading branch information
TessaIO committed Jul 29, 2023
1 parent b90d2ea commit 2263884
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions source/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func getFeaturesFromFiles() (map[string]string, error) {
}

if expiryDate.Before(time.Now()) {
klog.InfoS("feature file is expired", "fileName", fileName)
continue
}

Expand All @@ -304,9 +305,9 @@ func getExpirationDate(lines [][]byte) (time.Time, error) {
lineSplit := strings.SplitN(string(line), ":", 2)

key := lineSplit[0]

if key == ExpiryDateKey {
expiryDate, err := time.Parse(time.RFC3339, lineSplit[1])
expiryDate, err := time.Parse(time.RFC3339, strings.TrimSpace(lineSplit[1]))
fmt.Println(err)
if err != nil {
return time.Now(), err
}
Expand Down
21 changes: 21 additions & 0 deletions source/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ limitations under the License.
package local

import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand All @@ -33,3 +35,22 @@ func TestLocalSource(t *testing.T) {
assert.Empty(t, l)

}

func TestGetExpirationDate(t *testing.T) {

expectedDate := "2023-07-28T11:22:33Z"
fileContent := []string{
fmt.Sprintf("# +expiry-time: %v", expectedDate),
"featureKey=featureValue",
}

fileContentByte := [][]byte{}

for _, content := range fileContent {
fileContentByte = append(fileContentByte, []byte(content))
}

expirationDate, err := getExpirationDate(fileContentByte)
assert.Nil(t, err)
assert.Equal(t, expirationDate.Format(time.RFC3339), expectedDate)
}

0 comments on commit 2263884

Please sign in to comment.