• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ctfer-io / victor / 16761253499

05 Aug 2025 09:02PM UTC coverage: 0.0%. Remained the same
16761253499

push

github

web-flow
fix(#241): add `destroy-if-non-empty` flag (#257)

Signed-off-by: Lucas Tesson <lucastesson@protonmail.com>

0 of 53 new or added lines in 5 files covered. (0.0%)

1 existing line in 1 file now uncovered.

0 of 324 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/stack.go
1
package victor
2

3
import (
4
        "bytes"
5
        "context"
6
        "io"
7
        "net/http"
8

9
        "github.com/pkg/errors"
10
        "github.com/pulumi/pulumi/sdk/v3/go/auto"
11
        "github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
12
)
13

14
// GetStack fetches the Pulumi stack state file from the provided url,
15
// and if it does not exist, create a brand new one.
NEW
16
func GetStack(ctx context.Context, cli *Client, ws auto.Workspace, url string, verbose bool) (auto.Stack, error) {
×
17
        // TODO extract the stack from the url ? or the workspace ?
×
18
        stackName := "victor"
×
19
        logger := Log()
×
20

×
21
        // Get stack
×
22
        stack, err := auto.UpsertStack(ctx, stackName, ws)
×
23
        if err != nil {
×
24
                return auto.Stack{}, errors.Wrapf(err, "while upserting stack %s", stackName)
×
25
        }
×
26

27
        // Get state from webserver if exist
28
        req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
×
NEW
29
        res, err := cli.Do(req)
×
30
        if err != nil {
×
31
                return auto.Stack{}, errors.Wrapf(err, "while fetching %s", url)
×
32
        }
×
33
        defer func() {
×
34
                _ = res.Body.Close()
×
35
        }()
×
36

37
        if res.StatusCode == http.StatusNotFound {
×
38
                if verbose {
×
39
                        logger.Info("stack file not found, starting from a brand new one")
×
40
                }
×
41
                return stack, nil
×
42
        }
43

44
        if verbose {
×
45
                logger.Info("loading existing stack")
×
46
        }
×
47

48
        // Load state
49
        state, err := io.ReadAll(res.Body)
×
50
        if err != nil {
×
51
                return auto.Stack{}, errors.Wrapf(err, "while reading file at %s", url)
×
52
        }
×
53

54
        udep := apitype.UntypedDeployment{
×
55
                Version: 3, // Pulumi v3
×
56
        }
×
57
        if err := udep.Deployment.UnmarshalJSON(state); err != nil {
×
58
                return auto.Stack{}, errors.Wrap(err, "while unmarshalling state")
×
59
        }
×
60
        if err := stack.Import(ctx, udep); err != nil {
×
61
                return auto.Stack{}, errors.Wrap(err, "while importing state")
×
62
        }
×
63

64
        return stack, nil
×
65
}
66

67
// PushStack sends the Pulumi stack state file to the provided url.
68
func PushStack(ctx context.Context, client *Client, stack auto.Stack, url string) error {
×
69
        // Export state
×
70
        udep, err := stack.Export(ctx)
×
71
        if err != nil {
×
72
                return errors.Wrap(err, "while exporting state")
×
73
        }
×
74
        state, _ := udep.Deployment.MarshalJSON()
×
75

×
76
        // Send it to the webserver
×
77
        req, _ := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewBuffer(state))
×
78
        res, err := client.Do(req)
×
79
        if err != nil {
×
80
                return errors.Wrapf(err, "while sending state to %s", url)
×
81
        }
×
82
        defer func() {
×
83
                _ = res.Body.Close()
×
84
        }()
×
85

86
        return nil
×
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc