chore: add echo helper to create an agent with token (#6576)

This should reduce some LOC and duplication in tests!
This commit is contained in:
Kyle Carberry
2023-03-21 13:03:38 -05:00
committed by GitHub
parent d05b48267a
commit aaa3b31a0b
11 changed files with 84 additions and 363 deletions

View File

@ -11,6 +11,7 @@ import (
"golang.org/x/xerrors"
protobuf "google.golang.org/protobuf/proto"
"github.com/google/uuid"
"github.com/spf13/afero"
"github.com/coder/coder/provisionersdk"
@ -32,6 +33,28 @@ func ParameterSucceed() string {
return formatExecValue(successKey, "")
}
// ProvisionApplyWithAgent returns provision responses that will mock a fake
// "aws_instance" resource with an agent that has the given auth token.
func ProvisionApplyWithAgent(authToken string) []*proto.Provision_Response {
return []*proto.Provision_Response{{
Type: &proto.Provision_Response_Complete{
Complete: &proto.Provision_Complete{
Resources: []*proto.Resource{{
Name: "example",
Type: "aws_instance",
Agents: []*proto.Agent{{
Id: uuid.NewString(),
Name: "example",
Auth: &proto.Agent_Token{
Token: authToken,
},
}},
}},
},
},
}}
}
func formatExecValue(key, value string) string {
return fmt.Sprintf("%s=%s", key, value)
}