Skip to content

Commit

Permalink
test: use must, one must
Browse files Browse the repository at this point in the history
  • Loading branch information
gulducat committed Jan 10, 2023
1 parent 90d81ba commit f81d0b5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions nomad/structs/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,29 +1325,29 @@ func TestConsulIngressService_Validate(t *testing.T) {
err := (&ConsulIngressService{
Name: "",
}).Validate("http")
require.EqualError(t, err, "Consul Ingress Service requires a name")
must.EqError(t, err, "Consul Ingress Service requires a name")
})

t.Run("tcp extraneous hosts", func(t *testing.T) {
err := (&ConsulIngressService{
Name: "service1",
Hosts: []string{"host1"},
}).Validate("tcp")
require.EqualError(t, err, `Consul Ingress Service doesn't support associating hosts to a service for the "tcp" protocol`)
must.EqError(t, err, `Consul Ingress Service doesn't support associating hosts to a service for the "tcp" protocol`)
})

t.Run("tcp ok", func(t *testing.T) {
err := (&ConsulIngressService{
Name: "service1",
}).Validate("tcp")
require.NoError(t, err)
must.NoError(t, err)
})

t.Run("tcp with wildcard service", func(t *testing.T) {
err := (&ConsulIngressService{
Name: "*",
}).Validate("tcp")
require.EqualError(t, err, `Consul Ingress Service doesn't support wildcard name for "tcp" protocol`)
must.EqError(t, err, `Consul Ingress Service doesn't support wildcard name for "tcp" protocol`)
})

// non-"tcp" protocols should be all treated the same.
Expand All @@ -1357,29 +1357,29 @@ func TestConsulIngressService_Validate(t *testing.T) {
Name: "service1",
Hosts: []string{"host1"},
}).Validate(proto)
require.NoError(t, err)
must.NoError(t, err)
})

t.Run(proto+" without hosts", func(t *testing.T) {
err := (&ConsulIngressService{
Name: "service1",
}).Validate(proto)
require.NoErrorf(t, err, `should not require hosts with "%s" protocol`, proto)
must.NoError(t, err, must.Sprintf(`"%s" protocol should not require hosts`, proto))
})

t.Run(proto+" wildcard service", func(t *testing.T) {
err := (&ConsulIngressService{
Name: "*",
}).Validate(proto)
require.NoErrorf(t, err, `should allow wildcard hosts with "%s" protocol`, proto)
must.NoError(t, err, must.Sprintf(`"%s" protocol should allow wildcard service`, proto))
})

t.Run(proto+" wildcard service and host", func(t *testing.T) {
err := (&ConsulIngressService{
Name: "*",
Hosts: []string{"any"},
}).Validate(proto)
require.EqualError(t, err, `Consul Ingress Service with a wildcard "*" service name can not also specify hosts`)
must.EqError(t, err, `Consul Ingress Service with a wildcard "*" service name can not also specify hosts`)
})
}
}
Expand Down

0 comments on commit f81d0b5

Please sign in to comment.