github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/version/version_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package version
     5  
     6  import (
     7  	"regexp"
     8  	"strings"
     9  	"testing"
    10  )
    11  
    12  // Smoke test to validate that the version file can be read correctly and all exported
    13  // variables include the expected information.
    14  func TestVersion(t *testing.T) {
    15  	if match, _ := regexp.MatchString("[^\\d+\\.]", Version); match != false {
    16  		t.Fatalf("Version should contain only the main version")
    17  	}
    18  
    19  	if match, _ := regexp.MatchString("[^a-z\\d]", Prerelease); match != false {
    20  		t.Fatalf("Prerelease should contain only letters and numbers")
    21  	}
    22  
    23  	if SemVer.Prerelease() != "" {
    24  		t.Fatalf("SemVer should not include prerelease information")
    25  	}
    26  
    27  	if !strings.Contains(String(), Prerelease) {
    28  		t.Fatalf("Full version string should include prerelease information")
    29  	}
    30  }