| 12 | ) |
| 13 | |
| 14 | func Test_Config(t *testing.T) { |
| 15 | t.Parallel() |
| 16 | |
| 17 | id := uuid.New() |
| 18 | cases := []struct { |
| 19 | name string |
| 20 | config agentconn.Config |
| 21 | errContains string |
| 22 | }{ |
| 23 | { |
| 24 | name: "OK", |
| 25 | config: agentconn.Config{ |
| 26 | AgentID: id, |
| 27 | ConnectionMode: agentconn.ConnectionModeDirect, |
| 28 | HoldDuration: httpapi.Duration(time.Minute), |
| 29 | Connections: []agentconn.Connection{ |
| 30 | { |
| 31 | URL: "http://localhost:8080/path", |
| 32 | Interval: httpapi.Duration(time.Second), |
| 33 | Timeout: httpapi.Duration(time.Second), |
| 34 | }, |
| 35 | { |
| 36 | URL: "http://localhost:8000/differentpath", |
| 37 | Interval: httpapi.Duration(2 * time.Second), |
| 38 | Timeout: httpapi.Duration(2 * time.Second), |
| 39 | }, |
| 40 | }, |
| 41 | }, |
| 42 | }, |
| 43 | { |
| 44 | name: "NoAgentID", |
| 45 | config: agentconn.Config{ |
| 46 | AgentID: uuid.Nil, |
| 47 | ConnectionMode: agentconn.ConnectionModeDirect, |
| 48 | HoldDuration: 0, |
| 49 | Connections: nil, |
| 50 | }, |
| 51 | errContains: "agent_id must be set", |
| 52 | }, |
| 53 | { |
| 54 | name: "NoConnectionMode", |
| 55 | config: agentconn.Config{ |
| 56 | AgentID: id, |
| 57 | ConnectionMode: "", |
| 58 | HoldDuration: 0, |
| 59 | Connections: nil, |
| 60 | }, |
| 61 | errContains: "connection_mode must be set", |
| 62 | }, |
| 63 | { |
| 64 | name: "InvalidConnectionMode", |
| 65 | config: agentconn.Config{ |
| 66 | AgentID: id, |
| 67 | ConnectionMode: "blah", |
| 68 | HoldDuration: 0, |
| 69 | Connections: nil, |
| 70 | }, |
| 71 | errContains: "invalid connection_mode", |