mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix(provisioner): handle multiple agents, apps, scripts and envs (#13741)
This commit is contained in:
@ -219,6 +219,150 @@ func TestConvertResources(t *testing.T) {
|
||||
}},
|
||||
}},
|
||||
},
|
||||
"multiple-agents-multiple-apps": {
|
||||
resources: []*proto.Resource{{
|
||||
Name: "dev1",
|
||||
Type: "null_resource",
|
||||
Agents: []*proto.Agent{{
|
||||
Name: "dev1",
|
||||
OperatingSystem: "linux",
|
||||
Architecture: "amd64",
|
||||
Apps: []*proto.App{
|
||||
{
|
||||
Slug: "app1",
|
||||
DisplayName: "app1",
|
||||
// Subdomain defaults to false if unspecified.
|
||||
Subdomain: false,
|
||||
},
|
||||
{
|
||||
Slug: "app2",
|
||||
DisplayName: "app2",
|
||||
Subdomain: true,
|
||||
Healthcheck: &proto.Healthcheck{
|
||||
Url: "http://localhost:13337/healthz",
|
||||
Interval: 5,
|
||||
Threshold: 6,
|
||||
},
|
||||
},
|
||||
},
|
||||
Auth: &proto.Agent_Token{},
|
||||
ConnectionTimeoutSeconds: 120,
|
||||
DisplayApps: &displayApps,
|
||||
}},
|
||||
}, {
|
||||
Name: "dev2",
|
||||
Type: "null_resource",
|
||||
Agents: []*proto.Agent{{
|
||||
Name: "dev2",
|
||||
OperatingSystem: "linux",
|
||||
Architecture: "amd64",
|
||||
Apps: []*proto.App{
|
||||
{
|
||||
Slug: "app3",
|
||||
DisplayName: "app3",
|
||||
Subdomain: false,
|
||||
},
|
||||
},
|
||||
Auth: &proto.Agent_Token{},
|
||||
ConnectionTimeoutSeconds: 120,
|
||||
DisplayApps: &displayApps,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
"multiple-agents-multiple-envs": {
|
||||
resources: []*proto.Resource{{
|
||||
Name: "dev1",
|
||||
Type: "null_resource",
|
||||
Agents: []*proto.Agent{{
|
||||
Name: "dev1",
|
||||
OperatingSystem: "linux",
|
||||
Architecture: "amd64",
|
||||
ExtraEnvs: []*proto.Env{
|
||||
{
|
||||
Name: "ENV_1",
|
||||
Value: "Env 1",
|
||||
},
|
||||
{
|
||||
Name: "ENV_2",
|
||||
Value: "Env 2",
|
||||
},
|
||||
},
|
||||
Auth: &proto.Agent_Token{},
|
||||
ConnectionTimeoutSeconds: 120,
|
||||
DisplayApps: &displayApps,
|
||||
}},
|
||||
}, {
|
||||
Name: "dev2",
|
||||
Type: "null_resource",
|
||||
Agents: []*proto.Agent{{
|
||||
Name: "dev2",
|
||||
OperatingSystem: "linux",
|
||||
Architecture: "amd64",
|
||||
ExtraEnvs: []*proto.Env{
|
||||
{
|
||||
Name: "ENV_3",
|
||||
Value: "Env 3",
|
||||
},
|
||||
},
|
||||
Auth: &proto.Agent_Token{},
|
||||
ConnectionTimeoutSeconds: 120,
|
||||
DisplayApps: &displayApps,
|
||||
}},
|
||||
}, {
|
||||
Name: "env1",
|
||||
Type: "coder_env",
|
||||
}, {
|
||||
Name: "env2",
|
||||
Type: "coder_env",
|
||||
}, {
|
||||
Name: "env3",
|
||||
Type: "coder_env",
|
||||
}},
|
||||
},
|
||||
"multiple-agents-multiple-scripts": {
|
||||
resources: []*proto.Resource{{
|
||||
Name: "dev1",
|
||||
Type: "null_resource",
|
||||
Agents: []*proto.Agent{{
|
||||
Name: "dev1",
|
||||
OperatingSystem: "linux",
|
||||
Architecture: "amd64",
|
||||
Scripts: []*proto.Script{
|
||||
{
|
||||
DisplayName: "Foobar Script 1",
|
||||
Script: "echo foobar 1",
|
||||
RunOnStart: true,
|
||||
},
|
||||
{
|
||||
DisplayName: "Foobar Script 2",
|
||||
Script: "echo foobar 2",
|
||||
RunOnStart: true,
|
||||
},
|
||||
},
|
||||
Auth: &proto.Agent_Token{},
|
||||
ConnectionTimeoutSeconds: 120,
|
||||
DisplayApps: &displayApps,
|
||||
}},
|
||||
}, {
|
||||
Name: "dev2",
|
||||
Type: "null_resource",
|
||||
Agents: []*proto.Agent{{
|
||||
Name: "dev2",
|
||||
OperatingSystem: "linux",
|
||||
Architecture: "amd64",
|
||||
Scripts: []*proto.Script{
|
||||
{
|
||||
DisplayName: "Foobar Script 3",
|
||||
Script: "echo foobar 3",
|
||||
RunOnStart: true,
|
||||
},
|
||||
},
|
||||
Auth: &proto.Agent_Token{},
|
||||
ConnectionTimeoutSeconds: 120,
|
||||
DisplayApps: &displayApps,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
// Tests fetching metadata about workspace resources.
|
||||
"resource-metadata": {
|
||||
resources: []*proto.Resource{{
|
||||
@ -565,6 +709,18 @@ func TestConvertResources(t *testing.T) {
|
||||
sortResources(state.Resources)
|
||||
sortExternalAuthProviders(state.ExternalAuthProviders)
|
||||
|
||||
for _, resource := range state.Resources {
|
||||
for _, agent := range resource.Agents {
|
||||
agent.Id = ""
|
||||
if agent.GetToken() != "" {
|
||||
agent.Auth = &proto.Agent_Token{}
|
||||
}
|
||||
if agent.GetInstanceId() != "" {
|
||||
agent.Auth = &proto.Agent_InstanceId{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expectedNoMetadata := make([]*proto.Resource, 0)
|
||||
for _, resource := range expected.resources {
|
||||
resourceCopy, _ := protobuf.Clone(resource).(*proto.Resource)
|
||||
@ -642,7 +798,6 @@ func TestConvertResources(t *testing.T) {
|
||||
var resourcesMap []map[string]interface{}
|
||||
err = json.Unmarshal(data, &resourcesMap)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, expectedMap, resourcesMap)
|
||||
require.ElementsMatch(t, expected.externalAuthProviders, state.ExternalAuthProviders)
|
||||
})
|
||||
@ -911,6 +1066,12 @@ func sortResources(resources []*proto.Resource) {
|
||||
sort.Slice(agent.Apps, func(i, j int) bool {
|
||||
return agent.Apps[i].Slug < agent.Apps[j].Slug
|
||||
})
|
||||
sort.Slice(agent.ExtraEnvs, func(i, j int) bool {
|
||||
return agent.ExtraEnvs[i].Name < agent.ExtraEnvs[j].Name
|
||||
})
|
||||
sort.Slice(agent.Scripts, func(i, j int) bool {
|
||||
return agent.Scripts[i].DisplayName < agent.Scripts[j].DisplayName
|
||||
})
|
||||
}
|
||||
sort.Slice(resource.Agents, func(i, j int) bool {
|
||||
return resource.Agents[i].Name < resource.Agents[j].Name
|
||||
|
Reference in New Issue
Block a user