9
9
"os"
10
10
"path/filepath"
11
11
"reflect"
12
+ "strings"
12
13
"syscall"
13
14
"testing"
14
15
"time"
@@ -17,11 +18,13 @@ import (
17
18
"github.com/golang/snappy"
18
19
"github.com/hashicorp/nomad/client/allocdir"
19
20
"github.com/hashicorp/nomad/client/config"
21
+ "github.com/hashicorp/nomad/client/driver/env"
20
22
cstructs "github.com/hashicorp/nomad/client/structs"
21
23
"github.com/hashicorp/nomad/client/vaultclient"
22
24
"github.com/hashicorp/nomad/nomad/mock"
23
25
"github.com/hashicorp/nomad/nomad/structs"
24
26
"github.com/hashicorp/nomad/testutil"
27
+ "github.com/kr/pretty"
25
28
)
26
29
27
30
func testLogger () * log.Logger {
@@ -1615,6 +1618,87 @@ func TestTaskRunner_Pre06ScriptCheck(t *testing.T) {
1615
1618
t .Run (run ("0.5.6" , "mock_driver" , "tcp" , false ))
1616
1619
}
1617
1620
1621
+ func TestTaskRunner_interpolateServices (t * testing.T ) {
1622
+ t .Parallel ()
1623
+ task := & structs.Task {
1624
+ Services : []* structs.Service {
1625
+ {
1626
+ Name : "${name}" ,
1627
+ PortLabel : "${portlabel}" ,
1628
+ Tags : []string {"${tags}" },
1629
+ Checks : []* structs.ServiceCheck {
1630
+ {
1631
+ Name : "${checkname}" ,
1632
+ Type : "${checktype}" ,
1633
+ Command : "${checkcmd}" ,
1634
+ Args : []string {"${checkarg}" },
1635
+ Path : "${checkstr}" ,
1636
+ Protocol : "${checkproto}" ,
1637
+ PortLabel : "${checklabel}" ,
1638
+ InitialStatus : "${checkstatus}" ,
1639
+ Method : "${checkmethod}" ,
1640
+ Header : map [string ][]string {
1641
+ "${checkheaderk}" : {"${checkheaderv}" },
1642
+ },
1643
+ },
1644
+ },
1645
+ },
1646
+ },
1647
+ }
1648
+
1649
+ env := & env.TaskEnv {
1650
+ EnvMap : map [string ]string {
1651
+ "name" : "name" ,
1652
+ "portlabel" : "portlabel" ,
1653
+ "tags" : "tags" ,
1654
+ "checkname" : "checkname" ,
1655
+ "checktype" : "checktype" ,
1656
+ "checkcmd" : "checkcmd" ,
1657
+ "checkarg" : "checkarg" ,
1658
+ "checkstr" : "checkstr" ,
1659
+ "checkpath" : "checkpath" ,
1660
+ "checkproto" : "checkproto" ,
1661
+ "checklabel" : "checklabel" ,
1662
+ "checkstatus" : "checkstatus" ,
1663
+ "checkmethod" : "checkmethod" ,
1664
+ "checkheaderk" : "checkheaderk" ,
1665
+ "checkheaderv" : "checkheaderv" ,
1666
+ },
1667
+ }
1668
+
1669
+ interpTask := interpolateServices (env , task )
1670
+
1671
+ exp := & structs.Task {
1672
+ Services : []* structs.Service {
1673
+ {
1674
+ Name : "name" ,
1675
+ PortLabel : "portlabel" ,
1676
+ Tags : []string {"tags" },
1677
+ Checks : []* structs.ServiceCheck {
1678
+ {
1679
+ Name : "checkname" ,
1680
+ Type : "checktype" ,
1681
+ Command : "checkcmd" ,
1682
+ Args : []string {"checkarg" },
1683
+ Path : "checkstr" ,
1684
+ Protocol : "checkproto" ,
1685
+ PortLabel : "checklabel" ,
1686
+ InitialStatus : "checkstatus" ,
1687
+ Method : "checkmethod" ,
1688
+ Header : map [string ][]string {
1689
+ "checkheaderk" : {"checkheaderv" },
1690
+ },
1691
+ },
1692
+ },
1693
+ },
1694
+ },
1695
+ }
1696
+
1697
+ if diff := pretty .Diff (interpTask , exp ); len (diff ) > 0 {
1698
+ t .Fatalf ("diff:\n %s\n " , strings .Join (diff , "\n " ))
1699
+ }
1700
+ }
1701
+
1618
1702
func TestTaskRunner_ShutdownDelay (t * testing.T ) {
1619
1703
t .Parallel ()
1620
1704
0 commit comments