github.com/drone/runner-go@v1.12.0/environ/semver_test.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package environ
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/google/go-cmp/cmp"
    11  )
    12  
    13  func TestInvalidSemver(t *testing.T) {
    14  	a := versions("this is an invalid version")
    15  	b := map[string]string{"DRONE_SEMVER_ERROR": "this is an invalid version is not in dotted-tri format"}
    16  	if diff := cmp.Diff(a, b); diff != "" {
    17  		t.Errorf("Unexpected semver variables")
    18  		t.Log(diff)
    19  	}
    20  }
    21  
    22  func TestSemver(t *testing.T) {
    23  	a := versions("v1.2.3-alpha+001")
    24  	b := map[string]string{
    25  		"DRONE_SEMVER":            "1.2.3-alpha+001",
    26  		"DRONE_SEMVER_MAJOR":      "1",
    27  		"DRONE_SEMVER_MINOR":      "2",
    28  		"DRONE_SEMVER_PATCH":      "3",
    29  		"DRONE_SEMVER_SHORT":      "1.2.3",
    30  		"DRONE_SEMVER_PRERELEASE": "alpha",
    31  		"DRONE_SEMVER_BUILD":      "001",
    32  	}
    33  	if diff := cmp.Diff(a, b); diff != "" {
    34  		t.Errorf("Unexpected semver variables")
    35  		t.Log(diff)
    36  	}
    37  }