Skip to content

Commit

Permalink
Add new source header
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Aug 8, 2023
1 parent 7450e23 commit 12bef1b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions provider/pkg/internal/pulumiapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ func (c *Client) createRequest(ctx context.Context, method, path string, reqBody
}

// add default headers
req.Header.Add("X-Pulumi-Source", "provider")
req.Header.Add("Accept", "application/vnd.pulumi+8")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "token "+c.token)

return req, nil
}

Expand Down
34 changes: 33 additions & 1 deletion provider/pkg/internal/pulumiapi/deployment_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDeploymentSettings(t *testing.T) {
func TestGetDeploymentSettings(t *testing.T) {

orgName := "an-organization"
projectName := "a-project"
Expand Down Expand Up @@ -63,3 +63,35 @@ func TestDeploymentSettings(t *testing.T) {
assert.Nil(t, err, "err should be nil since error was returned")
})
}

func TestCreateDeploymentSettings(t *testing.T) {

orgName := "an-organization"
projectName := "a-project"
stackName := "a-stack"

t.Run("Happy Path", func(t *testing.T) {
dsValue := DeploymentSettings{
OperationContext: &OperationContext{},
GitHub: &GitHubConfiguration{},
SourceContext: &apitype.SourceContext{},
ExecutorContext: &apitype.ExecutorContext{},
}

c, cleanup := startTestServer(t, testServerConfig{
ExpectedReqMethod: http.MethodPost,
ExpectedReqPath: "/" + path.Join("api", "preview", orgName, projectName, stackName, "deployment", "settings"),
ResponseCode: 201,
ExpectedReqBody: dsValue,
})
defer cleanup()

err := c.CreateDeploymentSettings(ctx, StackName{
OrgName: orgName,
ProjectName: projectName,
StackName: stackName,
}, dsValue)

assert.Nil(t, err)
})
}
1 change: 1 addition & 0 deletions provider/pkg/internal/pulumiapi/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func startTestServer(t *testing.T, config testServerConfig) (client *Client, cle
assert.Equal(t, "token "+token, r.Header.Get("Authorization"))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
assert.Equal(t, "application/vnd.pulumi+8", r.Header.Get("Accept"))
assert.Equal(t, "provider", r.Header.Get("X-Pulumi-Source"))

// if we expected a request body, unmarshal the body and
if config.ExpectedReqBody != nil {
Expand Down

0 comments on commit 12bef1b

Please sign in to comment.